A out-of-air lifetime that that may not live long vs. the implementation is not general enough #131821
Open
Description
opened on Oct 17, 2024
Code
fn test<F>(f:F)
where F: for<'b> FnOnce(&'b i32){}
fn main(){
test(|s:&'static i32|{});
}
Current output
--> src/main.rs:11:11
|
11 | test(|s:&'static i32|{});
| ^ help: if this is intentional, prefix it with an underscore: `_s`
error: lifetime may not live long enough
--> src/main.rs:11:11
|
11 | test(|s:&'static i32|{});
| ^ - let's call the lifetime of this reference `'1`
| |
| requires that `'1` must outlive `'static`
Desired output
The implementation is not general enough
Rationale and extra context
The closure parameter is explicitly specified as &'static i32
, where does the lifetime 'l
come from? Moreover, the lifetime 'static
should outlive any lifetime, however, the diagnosis instead says
lifetime may not live long enough
Presumably, the implementation of trait FnOnce
for the closure type is only for 'static
, which is not general enough.
Other cases
No response
Rust Version
rustc 1.81.0 (eeb90cd 2024-09-04)
binary: rustc
commit-hash: eeb90cd
commit-date: 2024-09-04
host: x86_64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7
Anything else?
No response
Metadata
Assignees
Labels
Area: Non-lexical lifetimes (NLL)Area: Messages for errors, warnings, and lintsArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Diagnostics: Confusing error or lint that should be reworked.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.Working towards the "diagnostic parity" goalRelevant to the compiler team, which will review and decide on the PR/issue.
Activity