Skip to content

dont suggest changing the mutability of a borrow that comes from a macro - #162638

Open
Albab-Hasan wants to merge 1 commit into
rust-lang:mainfrom
Albab-Hasan:no-mut-borrow-suggestion-in-macro
Open

dont suggest changing the mutability of a borrow that comes from a macro#162638
Albab-Hasan wants to merge 1 commit into
rust-lang:mainfrom
Albab-Hasan:no-mut-borrow-suggestion-in-macro

Conversation

@Albab-Hasan

Copy link
Copy Markdown
Contributor

suggest_change_mut has no expansion guard so a borrow written in a macro body gets a MachineApplicable help pointing inside the macro or at a file in a dependency. with more than one local call site applying it forces the mutable borrow on every expansion and swaps E0525 for E0596. adds span.can_be_used_for_suggestions() to the guard falling through to the existing note.

with a single local call site the suggestion is correct. the span is the defect.

the guard is in the shared helper so it covers all three call sites. full tests/ui 21979 passed 0 failed with zero existing baselines re blessed.

r? @chenyukang

cc @davidtwco

the suggestion rewrote the borrow where it was written. for a borrow coming from a macro body that is the macro definition rather than the call site, and for a macro from another crate a file the user cannot edit. it was machine applicable so rustfix would apply it and a macro invoked at more than one call site could stop compiling.

gate it on can_be_used_for_suggestions so those cases fall through to the existing note that the trait is implemented for the mutable borrow but not the shared one.
@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 Sep 11, 2026
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.

3 participants