Open
Description
Code
fn main() {
consume_fn(identity);
}
fn identity(x: &u32) -> &u32 { x }
fn consume_fn<F>(_: impl FnOnce(&u32) -> F) {}
Current output
error[E0308]: mismatched types
--> ./t.rs:4:5
|
4 | consume_fn(identity);
| ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected reference `&_`
found reference `&_`
note: the lifetime requirement is introduced here
--> ./t.rs:9:42
|
9 | fn consume_fn<F>(_: impl FnOnce(&u32) -> F) {}
| ^
Desired output
error[E0308]: mismatched types
--> ./t.rs:4:5
|
4 | consume_fn(identity);
| ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected reference `&'1 _`
found reference `for<'2> &'2 _`
note: the lifetime requirement is introduced here
--> ./t.rs:9:42
|
9 | fn consume_fn<F>(_: impl FnOnce(&u32) -> F) {}
| ^
Rationale and extra context
Emitting expected/found with the same thing is not very helpful. Ideally we would also mention why the types can't be actually equal here (F
being a concrete type and not being able to mention the lifetime in FnOnce
), but I'm not sure how to best fit it in an error message.
Other cases
No response
Rust Version
rustc 1.79.0-nightly (ef8b9dcf2 2024-04-24)
binary: rustc
commit-hash: ef8b9dcf23700f2e2265317611460d3a65c19eff
commit-date: 2024-04-24
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4
Anything else?
No response