Skip to content

Fix duplicate lifetime parameter - #160378

Open
bb1yd wants to merge 1 commit into
rust-lang:mainfrom
bb1yd:fix-duplicate-lifetime-parameter
Open

Fix duplicate lifetime parameter#160378
bb1yd wants to merge 1 commit into
rust-lang:mainfrom
bb1yd:fix-duplicate-lifetime-parameter

Conversation

@bb1yd

@bb1yd bb1yd commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Closes #123713

The previous code suggest adding a higher-ranked lifetime for<'a> for regular case and explicit lifetime 'a for associated type. But it didn't check whether the lifetime 'a is already occupied and it never suggest the user to use the existing lifetime.

I think that it might be better if we put the diagnostics code for error E0637 together with E0106 in the same function add_missing_lifetime_specifiers_label, since they share some same logic.

The current code behaves differently when there are lifetimes in scope:

  • 0 lifetime available: same behaviour, suggest for<'a> (regular case) or 'a (associated type)
  • 1 lifetime available: suggest using this lifetime or create a new higher-ranked lifetime with a fresh name (for regular case)
  • multiple lifetime available: suggest using one of the lifetime or create a new higher-ranked lifetime with a fresh name (for regular case)

The help message of introducing HRTB changed to the same with E0106.

@rustbot rustbot added 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. labels Aug 2, 2026
@bb1yd bb1yd changed the title fix duplicate lifetime parameter Fix duplicate lifetime parameter Aug 2, 2026
@bb1yd
bb1yd force-pushed the fix-duplicate-lifetime-parameter branch 2 times, most recently from 3cb20ed to 77719b9 Compare August 3, 2026 06:51
@rust-log-analyzer

This comment has been minimized.

@bb1yd
bb1yd force-pushed the fix-duplicate-lifetime-parameter branch 4 times, most recently from 4238b42 to 403c96e Compare August 3, 2026 09:32
@bb1yd
bb1yd force-pushed the fix-duplicate-lifetime-parameter branch from 403c96e to 36b8615 Compare August 3, 2026 09:41
@bb1yd
bb1yd marked this pull request as ready for review August 3, 2026 11:24
@rustbot rustbot 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 Aug 3, 2026
@rustbot

rustbot commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

r? @mu001999

rustbot has assigned @mu001999.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 20 candidates

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.

rustc suggests for<'a> when lifetime param already exists

4 participants