Skip to content

borrowck: suggest explicit &_/&mut _for unannotated closure arguments - #163648

Open
raushan728 wants to merge 2 commits into
rust-lang:mainfrom
raushan728:issues/163475
Open

raushan728 wants to merge 2 commits into
rust-lang:mainfrom
raushan728:issues/163475

Conversation

@raushan728

@raushan728 raushan728 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #163475

Passing a borrow to an unannotated closure parameter forces the compiler to infer a single outer lifetime instead of a higher ranked one. This results in confusing E0597 (local) or E0716 (temporary) borrow errors.

  • Adds a diagnostic suggestion to explicitly annotate the closure argument to make it higher ranked
  • Supports both shared and mutable borrows, including partial type inferences
  • Automatically skips macros and already annotated parameters to ensure zero false positives

@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 2, 2026
@rust-log-analyzer

This comment has been minimized.

@rustbot

This comment has been minimized.

@GuillaumeGomez

Copy link
Copy Markdown
Member

r?

@rustbot

rustbot commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Error: Parsing assign command in comment failed: specify user to assign to (if you want to reroll without a specific reviewer in mind, use @rustbot reroll)

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@GuillaumeGomez

Copy link
Copy Markdown
Member

@rustbot reroll

@rustbot rustbot assigned davidtwco and unassigned GuillaumeGomez Oct 5, 2026
@raushan728

Copy link
Copy Markdown
Contributor Author

@rustbot reroll

@rustbot rustbot assigned TaKO8Ki and unassigned davidtwco Oct 23, 2026
@raushan728
raushan728 marked this pull request as draft October 27, 2026 05:18
@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 Oct 27, 2026
@raushan728 raushan728 changed the title borrowck: suggest explicit &_ annotations for unannotated closure arguments on E0597 borrowck: suggest explicit &_1/&mut _`for unannotated closure arguments on E0597and E0716 Oct 27, 2026
@raushan728 raushan728 changed the title borrowck: suggest explicit &_1/&mut _`for unannotated closure arguments on E0597and E0716 borrowck: suggest explicit &_1/&mut _for unannotated closure arguments on E0597and E0716 Oct 27, 2026
@raushan728 raushan728 changed the title borrowck: suggest explicit &_1/&mut _for unannotated closure arguments on E0597and E0716 borrowck: suggest explicit &_/&mut _for unannotated closure arguments on E0597and E0716 Oct 27, 2026
@raushan728 raushan728 changed the title borrowck: suggest explicit &_/&mut _for unannotated closure arguments on E0597and E0716 borrowck: suggest explicit &_/&mut _for unannotated closure arguments Oct 27, 2026
@raushan728
raushan728 marked this pull request as ready for review October 27, 2026 08:43
@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 Oct 27, 2026
@rust-log-analyzer

This comment has been minimized.

@rustbot

This comment has been minimized.

@raushan728

Copy link
Copy Markdown
Contributor Author

@rustbot reroll

@rustbot rustbot assigned chenyukang and unassigned tmiasko Nov 4, 2026
@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Nov 6, 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.

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-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.

Diagnostic: confusing output for closure type inference

8 participants