rust-lang / rust-lang/rust

A out-of-air lifetime that that may not live long vs. the implementation is not general enough

Open
#131,821 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-higher-ranked A-NLL D-confusing D-terse NLL-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7

Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the lifetime diagnostic from the example in src/main.rs with rustc 1.81.0 and compare it with the requested wording. Start by tracing how rustc reports the closure's FnOnce lifetime requirement; done means this case reports that the implementation is not general enough instead of claiming the lifetime may not live long enough.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.