Open
Description
Consider the following code (playground):
struct S<'a>(&'a str);
fn f(inner: fn(&str, &S)) {
}
#[allow(unreachable_code)]
fn main() {
let inner: fn(_, _) = unimplemented!();
f(inner);
}
Rustc gives an error:
error[E0308]: mismatched types
--> src/main.rs:9:7
|
9 | f(inner);
| ^^^^^ one type is more general than the other
|
= note: expected fn pointer `for<'r, 's, 't0> fn(&'r str, &'s S<'t0>)`
found fn pointer `fn(&str, &S<'_>)`
Here is the fixed code (playground):
let inner: fn(&str, &S<'_>) = unimplemented!();
f(inner);
In particular, the only thing that changed was fn(_, _)
-> fn(&str, &S<'_>)
. But this is exactly the type that was printed in the diagnostic originally! What changed?
I don't understand why this error was emitted, but it would at least be nice to suggest the transformation that makes the code work.
Reduced from rust-lang/crater#542.