rust-lang / rust-lang/rust

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

Open
#134,194 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-suggestion-diagnostics D-invalid-suggestion D-verbose F-precise_capturing P-low T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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)

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

Start with the reproducer in src/lib.rs and run it to compare the current diagnostics with the expected output. Trace the compiler diagnostic paths for an anonymous lifetime in a precise use<> capturing list, then ensure the invalid 'static suggestion is removed and the duplicate errors become one while preserving the borrowed-value hint.

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.