about summary refs log tree commit diff
path: root/src/test/ui/chalkify
diff options
context:
space:
mode:
authorscalexm <alexandre@scalexm.fr>2018-11-30 15:07:38 +0100
committerscalexm <alexandre@scalexm.fr>2018-12-27 19:21:16 +0100
commit81d6f9cc813e8946b6cb2ee29dffeb0000c63e69 (patch)
tree13bbab2db136b5bb30adda28df8dac8fd6bcaae2 /src/test/ui/chalkify
parent3790f08a42afd07835f9eec72db1d56235d32eed (diff)
Add tests
Diffstat (limited to 'src/test/ui/chalkify')
-rw-r--r--src/test/ui/chalkify/type_inference.rs26
-rw-r--r--src/test/ui/chalkify/type_inference.stderr28
2 files changed, 54 insertions, 0 deletions
diff --git a/src/test/ui/chalkify/type_inference.rs b/src/test/ui/chalkify/type_inference.rs
new file mode 100644
index 00000000000..62a53ec0317
--- /dev/null
+++ b/src/test/ui/chalkify/type_inference.rs
@@ -0,0 +1,26 @@
+// compile-flags: -Z chalk
+
+trait Foo { }
+impl Foo for i32 { }
+
+trait Bar { }
+impl Bar for i32 { }
+impl Bar for u32 { }
+
+fn only_foo<T: Foo>(_x: T) { }
+
+fn only_bar<T: Bar>(_x: T) { }
+
+fn main() {
+    let x = 5.0;
+
+    // The only type which implements `Foo` is `i32`, so the chalk trait solver
+    // is expecting a variable of type `i32`. This behavior differs from the
+    // old-style trait solver. I guess this will change, that's why I'm
+    // adding that test.
+    only_foo(x); //~ ERROR mismatched types
+
+    // Here we have two solutions so we get back the behavior of the old-style
+    // trait solver.
+    only_bar(x); //~ ERROR the trait bound `{float}: Bar` is not satisfied
+}
diff --git a/src/test/ui/chalkify/type_inference.stderr b/src/test/ui/chalkify/type_inference.stderr
new file mode 100644
index 00000000000..49ed97d7168
--- /dev/null
+++ b/src/test/ui/chalkify/type_inference.stderr
@@ -0,0 +1,28 @@
+error[E0308]: mismatched types
+  --> $DIR/type_inference.rs:21:14
+   |
+LL |     only_foo(x); //~ ERROR mismatched types
+   |              ^ expected i32, found floating-point variable
+   |
+   = note: expected type `i32`
+              found type `{float}`
+
+error[E0277]: the trait bound `{float}: Bar` is not satisfied
+  --> $DIR/type_inference.rs:25:5
+   |
+LL |     only_bar(x); //~ ERROR the trait bound `{float}: Bar` is not satisfied
+   |     ^^^^^^^^ the trait `Bar` is not implemented for `{float}`
+   |
+   = help: the following implementations were found:
+             <i32 as Bar>
+             <u32 as Bar>
+note: required by `only_bar`
+  --> $DIR/type_inference.rs:12:1
+   |
+LL | fn only_bar<T: Bar>(_x: T) { }
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+Some errors occurred: E0277, E0308.
+For more information about an error, try `rustc --explain E0277`.