Open
Description
Code
fn test() -> Option<impl Fn(&String)> {
if false {
return None;
}
Some(|_| {})
}
Current output
error: implementation of `Fn` is not general enough
--> src/lib.rs:3:16
|
3 | return None;
| ^^^^ implementation of `Fn` is not general enough
|
= note: closure with signature `fn(&'2 String)` must implement `Fn<(&'1 String,)>`, for any lifetime `'1`...
= note: ...but it actually implements `Fn<(&'2 String,)>`, for some specific lifetime `'2`
error: implementation of `FnOnce` is not general enough
--> src/lib.rs:3:16
|
3 | return None;
| ^^^^ implementation of `FnOnce` is not general enough
|
= note: closure with signature `fn(&'2 String)` must implement `FnOnce<(&'1 String,)>`, for any lifetime `'1`...
= note: ...but it actually implements `FnOnce<(&'2 String,)>`, for some specific lifetime `'2`
error: implementation of `Fn` is not general enough
--> src/lib.rs:5:5
|
5 | Some(|_| {})
| ^^^^^^^^^^^^ implementation of `Fn` is not general enough
|
= note: closure with signature `fn(&'0 String)` must implement `Fn<(&String,)>`, for some specific lifetime `'0`...
= note: ...but it actually implements `Fn<(&'1 String,)>`, for some specific lifetime `'1`
error: could not compile `playground` (lib) due to 3 previous errors
Desired output
I think ideally there would only be an error pointing at the actual closure and not None
.
Rationale and extra context
It's made worse that there are two errors on None
so the "good" error is buried further.
A broader issue is that this doesn't compile in the first place.
Other cases
Rust Version
1.88.0
Anything else?
No response
Metadata
Metadata
Assignees
Labels
Area: The borrow checkerArea: Messages for errors, warnings, and lintsArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Diagnostics: spans don't point to exactly the erroneous codeDiagnostics: Too much output caused by a single piece of incorrect code.Relevant to the compiler team, which will review and decide on the PR/issue.