Skip to content

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

Open
estebank wants to merge 1 commit into
rust-lang:mainfrom
estebank:issue-134194
Open

estebank wants to merge 1 commit into
rust-lang:mainfrom
estebank:issue-134194

Conversation

@estebank

@estebank estebank commented Jan 3, 2025

Copy link
Copy Markdown
Contributor
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
Comment thread compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

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

Copy link
Copy Markdown
Contributor

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<'_> {}.

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
Copy Markdown
Contributor

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
@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
Copy Markdown
Contributor

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"

@compiler-errors

Copy link
Copy Markdown
Contributor

@rustbot author

@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 23, 2025
@bors

bors commented Feb 11, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #127541) made this pull request unmergeable. Please resolve the merge conflicts.

```
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.
@bors

bors commented Apr 17, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #139938) made this pull request unmergeable. Please resolve the merge conflicts.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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

4 participants