Skip to content

borrowck: Don't mention unused vars in closure outlive errors#154674

Merged
rust-bors[bot] merged 3 commits intorust-lang:mainfrom
Enselic:unused-outlive
Apr 5, 2026
Merged

borrowck: Don't mention unused vars in closure outlive errors#154674
rust-bors[bot] merged 3 commits intorust-lang:mainfrom
Enselic:unused-outlive

Conversation

@Enselic
Copy link
Copy Markdown
Member

@Enselic Enselic commented Apr 1, 2026

When there is a closure arg lifetime error, the code does its best to find variables that correspond to the lifetimes involved. This commit stops mentioning arguments that are unused in closures, since they are not relevant. This removes the "red herring" of #113121.

The user_arg_index nomenclature can be applied more broadly, but then the diff becomes annoyingly big, so I chose not to do that.

Review each commit individually for a nicer experience.

The `user_arg_index` nomenclature can be applied more broadly, but then
the diff becomes annoyingly big, so I chose not to do that.
@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 Apr 1, 2026
Enselic added 2 commits April 1, 2026 12:17
So that the impact of the commit that fixes the test can be seen
clearly.
When there is a lifetime error, the code does its best to find variables
that correspond to the lifetimes involved. This commit stops mentioning
arguments that are unused in closures, since they are not relevant.

See the diff of the blessed test to get a good clue of what that means.
@Enselic Enselic marked this pull request as ready for review April 1, 2026 12:13
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 1, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 1, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 1, 2026

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
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: borrowck, compiler
  • borrowck, compiler expanded to 69 candidates
  • Random selection from 13 candidates

let mut used = false;
VisitPlacesWith(|place: Place<'_>, context: PlaceContext| {
if !matches!(context, PlaceContext::NonUse(_)) && place.local == target {
used = true;
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.

is there a way to break out here? We don't need to continue the visit

Copy link
Copy Markdown
Member Author

@Enselic Enselic Apr 2, 2026

Choose a reason for hiding this comment

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

I tried to find a way, but I don't think there is a way (without doing stuff like manually implementing a visitor specifically for this purpose, but IMHO that would be overkill). Luckily this code is only run in the face of compiler errors, so normal compilation speed is not affected.

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.

ok!

Comment thread compiler/rustc_borrowck/src/diagnostics/var_name.rs
Copy link
Copy Markdown
Contributor

@jdonszelmann jdonszelmann left a comment

Choose a reason for hiding this comment

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

looks good to me except the early return

View changes since this review

@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 Apr 2, 2026
@Enselic
Copy link
Copy Markdown
Member Author

Enselic commented Apr 2, 2026

@rustbot ready

@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 Apr 2, 2026
@jdonszelmann
Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 5, 2026

📌 Commit 94ee70e has been approved by jdonszelmann

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 Apr 5, 2026
rust-bors Bot pushed a commit that referenced this pull request Apr 5, 2026
…uwer

Rollup of 2 pull requests

Successful merges:

 - #154555 (Make sure we run the full suite, even when more specific filters are given)
 - #154674 (borrowck: Don't mention unused vars in closure outlive errors)
@rust-bors rust-bors Bot merged commit 9b2b299 into rust-lang:main Apr 5, 2026
11 checks passed
rust-timer added a commit that referenced this pull request Apr 5, 2026
Rollup merge of #154674 - Enselic:unused-outlive, r=jdonszelmann

borrowck: Don't mention unused vars in closure outlive errors

When there is a closure arg lifetime error, the code does its best to find variables that correspond to the lifetimes involved. This commit stops mentioning arguments that are unused in closures, since they are not relevant. This removes the "red herring" of #113121.

The `user_arg_index` nomenclature can be applied more broadly, but then the diff becomes annoyingly big, so I chose not to do that.

Review each commit individually for a nicer experience.
@rustbot rustbot added this to the 1.96.0 milestone Apr 5, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 20, 2026
…mann

borrowck: Apply `user_arg_index` nomenclature more broadly

No change in behavior. Only renames and a couple of added comments.

As requested here: rust-lang#154674 (comment)

r? jdonszelmann
rust-timer added a commit that referenced this pull request Apr 20, 2026
Rollup merge of #154895 - Enselic:user-arg-index, r=jdonszelmann

borrowck: Apply `user_arg_index` nomenclature more broadly

No change in behavior. Only renames and a couple of added comments.

As requested here: #154674 (comment)

r? jdonszelmann
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Apr 21, 2026
borrowck: Apply `user_arg_index` nomenclature more broadly

No change in behavior. Only renames and a couple of added comments.

As requested here: rust-lang/rust#154674 (comment)

r? jdonszelmann
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.

3 participants