Skip to content

undeclared raw lifetime; "consider introducing non-raw lifetime" #143150

@sodiboo

Description

@sodiboo

Code

fn a(_: dyn Trait + 'r#fn) { } trait Trait {}

Current output

error[E0261]: use of undeclared lifetime name `'fn` --> src/lib.rs:1:21 | 1 | fn a(_: dyn Trait + 'r#fn) { | ^^^^^ undeclared lifetime | help: consider introducing lifetime `'fn` here | 1 | fn a<'fn>(_: dyn Trait + 'r#fn) { | +++++

Desired output

error[E0261]: use of undeclared lifetime name `'r#fn` --> src/lib.rs:1:21 | 1 | fn a(_: dyn Trait + 'r#fn) { | ^^^^^ undeclared lifetime | help: consider introducing lifetime `'r#fn` here | 1 | fn a<'r#fn>(_: dyn Trait + 'r#fn) { | +++++++

Rationale and extra context

'fn, as the diagnostic currently suggests, is not a valid lifetime.

it is my understanding that for non-reserved lifetimes, something like 'r#a is supposed to be equivalent to 'a, and that the diagnostic would be correct, were it not for the fact that in this case the r# is mandatory or else it's a syntax error.

Rust Version

rustc 1.90.0-nightly (bdaba05a9 2025-06-27) binary: rustc commit-hash: bdaba05a953eb5abeba0011cdda2560d157aed2e commit-date: 2025-06-27 host: x86_64-unknown-linux-gnu release: 1.90.0-nightly LLVM version: 20.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.T-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