Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fmease opened this issue Dec 12, 2024 · 3 comments · May be fixed by #135052
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. F-precise_capturing `#![feature(precise_capturing)]` P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Dec 12, 2024

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)
@fmease fmease added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. F-precise_capturing `#![feature(precise_capturing)]` P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 12, 2024
@ionicmc-rs

This comment has been minimized.

@fmease

This comment has been minimized.

@ionicmc-rs

This comment has been minimized.

estebank added a commit to estebank/rust that referenced this issue Jan 3, 2025
```
error[E0106]: missing lifetime specifier
  --> $DIR/bad-lifetimes.rs:1:39
   |
LL | fn no_elided_lt() -> impl Sized + use<'_> {}
   |                                       ^^ expected named lifetime parameter
   |
help: consider introducing a named lifetime parameter
   |
LL | fn no_elided_lt<'a>() -> impl Sized + use<'a> {}
   |                ++++                       ~~
```

Fix rust-lang#134194.
estebank added a commit to estebank/rust that referenced this issue Jan 3, 2025
```
error[E0106]: missing lifetime specifier
  --> $DIR/bad-lifetimes.rs:1:39
   |
LL | fn no_elided_lt() -> impl Sized + use<'_> {}
   |                                       ^^ expected named lifetime parameter
   |
help: consider introducing a named lifetime parameter
   |
LL | fn no_elided_lt<'a>() -> impl Sized + use<'a> {}
   |                ++++                       ~~
```

Fix rust-lang#134194.
estebank added a commit to estebank/rust that referenced this issue Feb 13, 2025
```
error[E0106]: missing lifetime specifier
  --> $DIR/bad-lifetimes.rs:1:39
   |
LL | fn no_elided_lt() -> impl Sized + use<'_> {}
   |                                       ^^ expected named lifetime parameter
   |
help: consider introducing a named lifetime parameter
   |
LL | fn no_elided_lt<'a>() -> impl Sized + use<'a> {}
   |                ++++                       ~~
```

Fix rust-lang#134194.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. F-precise_capturing `#![feature(precise_capturing)]` P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants