about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2020-06-22 12:28:16 -0700
committerEsteban Küber <esteban@kuber.com.ar>2020-06-22 15:20:04 -0700
commitf84b7e1b052fd135ae2e754499b4fe286d5ba699 (patch)
treec8c910bf3359b602588affd5be512d2b1da68a2f /src/test/ui
parenta39c7787ba246353178e099373b9240be0d9e603 (diff)
Provide context on E0308 involving fn items
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/fn/fn-item-type.rs34
-rw-r--r--src/test/ui/fn/fn-item-type.stderr31
2 files changed, 55 insertions, 10 deletions
diff --git a/src/test/ui/fn/fn-item-type.rs b/src/test/ui/fn/fn-item-type.rs
index 68b75c18a43..256b9d45755 100644
--- a/src/test/ui/fn/fn-item-type.rs
+++ b/src/test/ui/fn/fn-item-type.rs
@@ -12,22 +12,44 @@ impl<T> Foo for T { /* `foo` is still default here */ }
 fn main() {
     eq(foo::<u8>, bar::<u8>);
     //~^ ERROR mismatched types
-    //~|  expected fn item `fn(_) -> _ {foo::<u8>}`
-    //~|  found fn item `fn(_) -> _ {bar::<u8>}`
-    //~|  expected fn item, found a different fn item
+    //~| expected fn item `fn(_) -> _ {foo::<u8>}`
+    //~| found fn item `fn(_) -> _ {bar::<u8>}`
+    //~| expected fn item, found a different fn item
+    //~| different `fn` items always have unique types, even if their signatures are the same
+    //~| change the expectation to require function pointer
+    //~| if the expectation is due to type inference, cast the expected `fn` to a function pointer
 
     eq(foo::<u8>, foo::<i8>);
     //~^ ERROR mismatched types
     //~| expected `u8`, found `i8`
+    //~| different `fn` items always have unique types, even if their signatures are the same
+    //~| change the expectation to require function pointer
+    //~| if the expectation is due to type inference, cast the expected `fn` to a function pointer
 
     eq(bar::<String>, bar::<Vec<u8>>);
     //~^ ERROR mismatched types
-    //~|  expected fn item `fn(_) -> _ {bar::<std::string::String>}`
-    //~|  found fn item `fn(_) -> _ {bar::<std::vec::Vec<u8>>}`
-    //~|  expected struct `std::string::String`, found struct `std::vec::Vec`
+    //~| expected fn item `fn(_) -> _ {bar::<std::string::String>}`
+    //~| found fn item `fn(_) -> _ {bar::<std::vec::Vec<u8>>}`
+    //~| expected struct `std::string::String`, found struct `std::vec::Vec`
+    //~| different `fn` items always have unique types, even if their signatures are the same
+    //~| change the expectation to require function pointer
+    //~| if the expectation is due to type inference, cast the expected `fn` to a function pointer
 
     // Make sure we distinguish between trait methods correctly.
     eq(<u8 as Foo>::foo, <u16 as Foo>::foo);
     //~^ ERROR mismatched types
     //~| expected `u8`, found `u16`
+    //~| different `fn` items always have unique types, even if their signatures are the same
+    //~| change the expectation to require function pointer
+    //~| if the expectation is due to type inference, cast the expected `fn` to a function pointer
+
+    eq(foo::<u8>, bar::<u8> as fn(isize) -> isize);
+    //~^ ERROR mismatched types
+    //~| expected fn item `fn(_) -> _ {foo::<u8>}`
+    //~| found fn pointer `fn(_) -> _`
+    //~| expected fn item, found fn pointer
+    //~| change the expectation to require function pointer
+    //~| if the expectation is due to type inference, cast the expected `fn` to a function pointer
+
+    eq(foo::<u8> as fn(isize) -> isize, bar::<u8>); // ok!
 }
diff --git a/src/test/ui/fn/fn-item-type.stderr b/src/test/ui/fn/fn-item-type.stderr
index 4cce25c43c4..84f5e034340 100644
--- a/src/test/ui/fn/fn-item-type.stderr
+++ b/src/test/ui/fn/fn-item-type.stderr
@@ -6,34 +6,57 @@ LL |     eq(foo::<u8>, bar::<u8>);
    |
    = note: expected fn item `fn(_) -> _ {foo::<u8>}`
               found fn item `fn(_) -> _ {bar::<u8>}`
+   = note: different `fn` items always have unique types, even if their signatures are the same
+   = help: change the expectation to require function pointer `fn(isize) -> isize`
+   = help: if the expectation is due to type inference, cast the expected `fn` to a function pointer: `foo::<u8> as fn(isize) -> isize`
 
 error[E0308]: mismatched types
-  --> $DIR/fn-item-type.rs:19:19
+  --> $DIR/fn-item-type.rs:22:19
    |
 LL |     eq(foo::<u8>, foo::<i8>);
    |                   ^^^^^^^^^ expected `u8`, found `i8`
    |
    = note: expected fn item `fn(_) -> _ {foo::<u8>}`
               found fn item `fn(_) -> _ {foo::<i8>}`
+   = note: different `fn` items always have unique types, even if their signatures are the same
+   = help: change the expectation to require function pointer `fn(isize) -> isize`
+   = help: if the expectation is due to type inference, cast the expected `fn` to a function pointer: `foo::<u8> as fn(isize) -> isize`
 
 error[E0308]: mismatched types
-  --> $DIR/fn-item-type.rs:23:23
+  --> $DIR/fn-item-type.rs:29:23
    |
 LL |     eq(bar::<String>, bar::<Vec<u8>>);
    |                       ^^^^^^^^^^^^^^ expected struct `std::string::String`, found struct `std::vec::Vec`
    |
    = note: expected fn item `fn(_) -> _ {bar::<std::string::String>}`
               found fn item `fn(_) -> _ {bar::<std::vec::Vec<u8>>}`
+   = note: different `fn` items always have unique types, even if their signatures are the same
+   = help: change the expectation to require function pointer `fn(isize) -> isize`
+   = help: if the expectation is due to type inference, cast the expected `fn` to a function pointer: `bar::<std::string::String> as fn(isize) -> isize`
 
 error[E0308]: mismatched types
-  --> $DIR/fn-item-type.rs:30:26
+  --> $DIR/fn-item-type.rs:39:26
    |
 LL |     eq(<u8 as Foo>::foo, <u16 as Foo>::foo);
    |                          ^^^^^^^^^^^^^^^^^ expected `u8`, found `u16`
    |
    = note: expected fn item `fn() {<u8 as Foo>::foo}`
               found fn item `fn() {<u16 as Foo>::foo}`
+   = note: different `fn` items always have unique types, even if their signatures are the same
+   = help: change the expectation to require function pointer `fn()`
+   = help: if the expectation is due to type inference, cast the expected `fn` to a function pointer: `<u8 as Foo>::foo as fn()`
 
-error: aborting due to 4 previous errors
+error[E0308]: mismatched types
+  --> $DIR/fn-item-type.rs:46:19
+   |
+LL |     eq(foo::<u8>, bar::<u8> as fn(isize) -> isize);
+   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected fn item, found fn pointer
+   |
+   = note: expected fn item `fn(_) -> _ {foo::<u8>}`
+           found fn pointer `fn(_) -> _`
+   = help: change the expectation to require function pointer `fn(isize) -> isize`
+   = help: if the expectation is due to type inference, cast the expected `fn` to a function pointer: `foo::<u8> as fn(isize) -> isize`
+
+error: aborting due to 5 previous errors
 
 For more information about this error, try `rustc --explain E0308`.