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

Emit single error for + use<'_> and don't suggest use<'static> #135052

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

estebank
Copy link
Contributor

@estebank estebank commented 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 #134194.

r? @compiler-errors

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 3, 2025
@@ -3118,7 +3121,9 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
}
}

if num_params == 0 {
if in_precise_capture {
err.note("`use<...>` precise captures list require a named lifetime");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not true. This works fine: fn foo(x: &u8) -> impl Sized + use<'_> {}.

@@ -4,33 +4,26 @@ error[E0106]: missing lifetime specifier
LL | fn no_elided_lt() -> 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably at least keep some explanation that justifies why '_ isn't valid without another lifetime which it can resolve to in the inputs.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels 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 estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 3, 2025
);
if in_precise_capture {
err.note(
"this function's return type specifies a borrowed `use<'_>` with an elided \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"a borrowed use<'_>" feels really awkward. I think this can be a bit more direct. Perhaps something like:

"cannot capture elided lifetime with use<'_> when there is no lifetime in scope to capture"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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