Skip to content

"late bound lifetime parameters" error should have a number and help text #80618

Closed
@cole-miller

Description

@cole-miller

Currently (tested on stable and nightly) if you try to compile this code

fn f<'a>() {}
fn main() { let _ = f::<'static>; }

you get this error message:

error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
 --> src/main.rs:4:17
  |
4 |     let _ = f::<'static>;
  |                 ^^^^^^^
  |
note: the late bound lifetime parameter is introduced here
 --> src/main.rs:1:6
  |
1 | fn f<'a>() {}
  |      ^^

There is no error number (like E0208) to pass to rustc --explain. There's also no mention that you can fix this error without changing the meaning of the code at all by putting a vacuous where clause in the signature of f, like this:

fn f<'a>() where 'a: 'a {}

See #42868 for background. (I'm not sure when that compatibility lint became a hard error; it seems to have happened without that tracking issue being updated. Maybe that has something to do with why the error has no number or help.)

I think:

  • this error should have a number and accompanying rustc --explain text that discusses the early- vs. late-bound lifetime distinction and why specifying late-bound lifetime parameters explicitly is not allowed
  • it should also have a help line that suggests adding where 'a: 'a

Here is the URLO thread that prompted this issue:

https://users.rust-lang.org/t/what-is-the-meaning-of-a-a-in-rust-lifetime-parameters/53570

cc @petrochenkov

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-error-codesArea: Explanation of an error code (--explain)A-lifetimesArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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