]> git.lizzy.rs Git - rust.git/blobdiff - crates/hir_ty/src/tests/coercion.rs
Merge #11842
[rust.git] / crates / hir_ty / src / tests / coercion.rs
index dd3b86f05033ad8d25216bebb22b44eebc4fdb0c..268faf8cb3a0643a7fb842f604af28213673393b 100644 (file)
@@ -2,12 +2,10 @@
 
 #[test]
 fn block_expr_type_mismatch() {
-    // FIXME fix double type mismatch
     check(
         r"
 fn test() {
     let a: i32 = { 1i64 };
-              // ^^^^^^^^ expected i32, got i64
                 // ^^^^ expected i32, got i64
 }
         ",
@@ -242,6 +240,45 @@ fn test() {
     );
 }
 
+#[test]
+fn coerce_autoderef_implication_1() {
+    check_no_mismatches(
+        r"
+//- minicore: deref
+struct Foo<T>;
+impl core::ops::Deref for Foo<u32> { type Target = (); }
+
+fn takes_ref_foo<T>(x: &Foo<T>) {}
+fn test() {
+    let foo = Foo;
+      //^^^ type: Foo<{unknown}>
+    takes_ref_foo(&foo);
+
+    let foo = Foo;
+      //^^^ type: Foo<u32>
+    let _: &() = &foo;
+}",
+    );
+}
+
+#[test]
+fn coerce_autoderef_implication_2() {
+    check(
+        r"
+//- minicore: deref
+struct Foo<T>;
+impl core::ops::Deref for Foo<u32> { type Target = (); }
+
+fn takes_ref_foo<T>(x: &Foo<T>) {}
+fn test() {
+    let foo = Foo;
+      //^^^ type: Foo<{unknown}>
+    let _: &u32 = &Foo;
+                //^^^^ expected &u32, got &Foo<{unknown}>
+}",
+    );
+}
+
 #[test]
 fn closure_return_coerce() {
     check_no_mismatches(