Skip to content

suggest named lifetimes instead of '_ in use<...> for E0700 - #163684

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
Albab-Hasan:name-anon-lifetimes-in-use-bound
Oct 23, 2026
Merged

rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
Albab-Hasan:name-anon-lifetimes-in-use-bound

Conversation

@Albab-Hasan

Copy link
Copy Markdown
Contributor

when a signature has more than one elided lifetime, the suggested use<'_> captures only the first in a case like fn f(_a: &u8, b: &T) -> impl Sized it stops resolving entirely and adds error[E0106] on top of the original error all at MachineApplicable.

when the hidden type captures more than one anonymous lifetime the suggestion now names them in the signature and lists those names in the bound which is the desired output from the issue. a signature with a single elided lifetime keeps the shorter use<'_>. this reuses the three-part shape AddPreciseCapturingAndParams already emits for argument-position impl Trait in the same function.

note. the argument-position impl Trait path in AddPreciseCapturingAndParams has the same defect when the signature also has elided reference lifetimes: fn f(_a: impl Sized, x: &u8, y: &u8) -> impl Sized still suggests use<'_, T> which produces E0106 plus the original E0700. it is MaybeIncorrect so rustfix does not apply it but the suggestion misleads. ill follow up on that.

the new test is //@ run-rustfix with a .fixed file that compiles which also let tests/ui/lifetimes/issue-105227.rs drop its FIXME(precise_capturing): Add rustfix here after dealing w/ elided lifetimes.

fixes #132199

r? @oli-obk

@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 Oct 3, 2026
Comment thread compiler/rustc_trait_selection/src/error_reporting/infer/region.rs
@Albab-Hasan
Albab-Hasan requested a review from oli-obk October 7, 2026 13:27
@Albab-Hasan
Albab-Hasan force-pushed the name-anon-lifetimes-in-use-bound branch from 40cda7b to e36e829 Compare October 14, 2026 10:46
@rustbot

This comment has been minimized.

@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

any updates?

@rust-bors

This comment has been minimized.

records current behaviour. for an anonymous lifetime the suggestion renders use<'_>, which resolves to the first elided lifetime in the signature. two of the cases here still fail after applying it, and one stops resolving entirely and reports a missing lifetime specifier on top of the original error.
for an anonymous lifetime the suggestion rendered use<'_>, which resolves to the first elided lifetime in the signature. with several of them it either captured the wrong one or stopped resolving and reported a missing lifetime specifier on top of the original error.

when the hidden type captures more than one anonymous lifetime the suggestion now names them in the signature and lists those names in the bound. a signature with a single elided lifetime keeps the shorter use<'_> form.

fixes rust-lang#132199
suggest_name_regions names several regions against one set of used names and adds the new generic parameters once, and suggest_name_region now delegates to it
@Albab-Hasan
Albab-Hasan force-pushed the name-anon-lifetimes-in-use-bound branch from e36e829 to 81b952e Compare October 21, 2026 09:55
@rustbot

rustbot commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@oli-obk

oli-obk commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

any updates?

sorry, was prepping for eurorust and then doing some travelling, reviews responsiveness should be back to my usual normal

emit_msg_span(err, prefix, description, span, suffix);
}

fn suggest_name_regions<'tcx>(

@oli-obk oli-obk Oct 23, 2026 •

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.

it's fine now, but for future contribs, please perform such movements in their own commit without also doing other changes in the same commit. This way it's easier to review as I don't also have to look out for behaviour changes in the code we're reusing

View changes since the review

@Albab-Hasan Albab-Hasan Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure ill keep that in mind and thanks for the review!

@oli-obk oli-obk left a comment •

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.

@rust-bors

rust-bors Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 81b952e has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 23, 2026
@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

any updates?

sorry, was prepping for eurorust and then doing some travelling, reviews responsiveness should be back to my usual normal

no problem and sry if the ping bothered you. hope you had fun in eurorust!

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 23, 2026
…-use-bound, r=oli-obk

suggest named lifetimes instead of `'_` in `use<...>` for E0700

when a signature has more than one elided lifetime, the suggested `use<'_>` captures only the first in a case like `fn f(_a: &u8, b: &T) -> impl Sized` it stops resolving entirely and adds `error[E0106]` on top of the original error all at `MachineApplicable`.

when the hidden type captures more than one anonymous lifetime the suggestion now names them in the signature and lists those names in the bound which is the desired output from the issue. a signature with a single elided lifetime keeps the shorter `use<'_>`. this reuses the three-part shape `AddPreciseCapturingAndParams` already emits for argument-position `impl Trait` in the same function.

note. the argument-position `impl Trait` path in `AddPreciseCapturingAndParams` has the same defect when the signature also has elided reference lifetimes: `fn f(_a: impl Sized, x: &u8, y: &u8) -> impl Sized` still suggests `use<'_, T>` which produces `E0106` plus the original `E0700`. it is `MaybeIncorrect` so rustfix does not apply it but the suggestion misleads. ill follow up on that.

the new test is `//@ run-rustfix` with a `.fixed` file that compiles which also let `tests/ui/lifetimes/issue-105227.rs` drop its `FIXME(precise_capturing): Add rustfix here after dealing w/ elided lifetimes`.

  fixes rust-lang#132199

  r? @oli-obk
rust-bors Bot pushed a commit that referenced this pull request Oct 23, 2026
Rollup of 9 pull requests

Successful merges:

 - #164792 (rustc_codegen_cranelift subtree update)
 - #163799 (std: keep value of `local_pointer!` until `thread_cleanup` is run)
 - #164781 (Bump dist-x86_64-illumos to Ubuntu 22.04)
 - #160902 (borrowck dataflow: respect borrow shallowness when killing borrows that conflict with assignments)
 - #163684 (suggest named lifetimes instead of `'_` in `use<...>` for E0700)
 - #164167 (Account for `use foo as bar;` on resolution error suggestions)
 - #164438 (Make async drop shim proxy pinned)
 - #164528 (Complete the various renamings of terms belonging to feature `checked_type_aliases`)
 - #164796 (miri: fix ICE when caller signature is c-variadic but callee is not)
@rust-bors
rust-bors Bot merged commit 4385065 into rust-lang:main Oct 23, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 23, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 23, 2026
Rollup merge of #163684 - Albab-Hasan:name-anon-lifetimes-in-use-bound, r=oli-obk

suggest named lifetimes instead of `'_` in `use<...>` for E0700

when a signature has more than one elided lifetime, the suggested `use<'_>` captures only the first in a case like `fn f(_a: &u8, b: &T) -> impl Sized` it stops resolving entirely and adds `error[E0106]` on top of the original error all at `MachineApplicable`.

when the hidden type captures more than one anonymous lifetime the suggestion now names them in the signature and lists those names in the bound which is the desired output from the issue. a signature with a single elided lifetime keeps the shorter `use<'_>`. this reuses the three-part shape `AddPreciseCapturingAndParams` already emits for argument-position `impl Trait` in the same function.

note. the argument-position `impl Trait` path in `AddPreciseCapturingAndParams` has the same defect when the signature also has elided reference lifetimes: `fn f(_a: impl Sized, x: &u8, y: &u8) -> impl Sized` still suggests `use<'_, T>` which produces `E0106` plus the original `E0700`. it is `MaybeIncorrect` so rustfix does not apply it but the suggestion misleads. ill follow up on that.

the new test is `//@ run-rustfix` with a `.fixed` file that compiles which also let `tests/ui/lifetimes/issue-105227.rs` drop its `FIXME(precise_capturing): Add rustfix here after dealing w/ elided lifetimes`.

  fixes #132199

  r? @oli-obk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

incorrect suggestion for use<...> bound that captures multiple lifetimes

3 participants