Skip to content

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Sep 29, 2025

When a binding needs to be mutably reborrowed multiple times, suggesting removing &mut will lead to follow up errors. Instead suggest both making the binding mutable and removing the reborrow.

error[E0596]: cannot borrow `outer` as mutable, as it is not declared as mutable --> f14.rs:2:12 | 2 | match (&mut outer, 23) { | ^^^^^^^^^^ cannot borrow as mutable | note: the binding is already a mutable borrow --> f14.rs:1:16 | 1 | fn test(outer: &mut Option<i32>) { | ^^^^^^^^^^^^^^^^ help: consider making the binding mutable if you need to reborrow multiple times | 1 | fn test(mut outer: &mut Option<i32>) { | +++ help: if there is only one mutable reborrow, remove the `&mut` | 2 - match (&mut outer, 23) { 2 + match (outer, 23) { | 

Address #81059.

When a binding needs to be mutably reborrowed multiple times, suggesting removing `&mut` will lead to follow up errors. Instead suggest both making the binding mutable and removing the reborrow. ``` error[E0596]: cannot borrow `outer` as mutable, as it is not declared as mutable --> f14.rs:2:12 | 2 | match (&mut outer, 23) { | ^^^^^^^^^^ cannot borrow as mutable | note: the binding is already a mutable borrow --> f14.rs:1:16 | 1 | fn test(outer: &mut Option<i32>) { | ^^^^^^^^^^^^^^^^ help: consider making the binding mutable if you need to reborrow multiple times | 1 | fn test(mut outer: &mut Option<i32>) { | +++ help: if there is only one mutable reborrow, remove the `&mut` | 2 - match (&mut outer, 23) { 2 + match (outer, 23) { | ```
@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 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 29, 2025

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
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

@bors
Copy link
Collaborator

bors commented Oct 12, 2025

☔ The latest upstream changes (presumably #142390) made this pull request unmergeable. Please resolve the merge conflicts.

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.

4 participants