Skip to content

Invalid suggestion on anonymous lifetime parameter in precise capturing list if there are no input lifetimes #134194

@fmease

Description

@fmease

Reproducer:

fn f() -> impl Sized + use<'_> {}

Current output:

error[E0106]: missing lifetime specifier
 --> src/lib.rs:1:28
  |
1 | fn f() -> impl Sized + use<'_> {}
  |                            ^^ expected named lifetime parameter
  |
  = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`, or if you will only have owned values
  |
1 | fn f() -> impl Sized + use<'static> {}
  |                            ~~~~~~~

error: expected lifetime parameter in `use<...>` precise captures list, found `'_`
 --> src/lib.rs:1:28
  |
1 | fn f() -> impl Sized + use<'_> {}
  |                            ^^

Expected:

  1. Don't suggest use<'static> which is invalid
  2. One diagnostic instead of two (while keeping the good hint this function's return type contains a borrowed value, but there is no value for it to be borrowed from)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.F-precise_capturing`#![feature(precise_capturing)]`P-lowLow priorityT-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