Skip to content

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

Open
@xmh0511

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 (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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)A-diagnosticsArea: Messages for errors, warnings, and lintsA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)D-confusingDiagnostics: Confusing error or lint that should be reworked.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.NLL-diagnosticsWorking towards the "diagnostic parity" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions