Skip to content

Suggest making binding mut on &mut reborrow - #147141

Merged
bors merged 1 commit into
rust-lang:masterfrom
estebank:issue-81059
Nov 4, 2025
Merged

Suggest making binding mut on &mut reborrow#147141
bors merged 1 commit into
rust-lang:masterfrom
estebank:issue-81059

Conversation

@estebank

@estebankestebank commented Sep 29, 2025

Copy link
Copy Markdown
Contributor

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.

@rustbotrustbot 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
Copy Markdown
Collaborator

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

bors commented Oct 12, 2025

Copy link
Copy Markdown
Collaborator

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

@BoxyUwU

Copy link
Copy Markdown
Member

r? compiler

@rustbotrustbot assigned jackh726 and unassigned BoxyUwUOct 21, 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) {
|
```
@rustbot

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master 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.

@jackh726jackh726 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay. Seems fine, if a little "here's a bit of guidance, but figure out if it applies to you".

View changes since this review

@jackh726

Copy link
Copy Markdown
Member

@bors r+ rollup

@bors

bors commented Nov 3, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 516a273 has been approved by jackh726

It is now in the queue for this repository.

@borsbors 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 Nov 3, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Nov 3, 2025
Suggest making binding `mut` on `&mut` reborrow
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 rust-lang#81059.
bors added a commit that referenced this pull request Nov 3, 2025
Rollup of 7 pull requests
Successful merges:
- #147141 (Suggest making binding `mut` on `&mut` reborrow)
- #147945 (Port `cfg!()` macro to the new attribute parsing system )
- #147951 (Add check for `+=` typo in let chains)
- #148004 (fix: Only special case single line item attribute suggestions)
- #148264 (reflect that type and const parameter can be intermixed)
- #148363 (Fix `wasm_import_module` attribute cross-crate)
- #148447 (Tweak E0401)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 549846e into rust-lang:masterNov 4, 2025
11 checks passed
@rustbotrustbot added this to the 1.93.0 milestone Nov 4, 2025
rust-timer added a commit that referenced this pull request Nov 4, 2025
Rollup merge of #147141 - estebank:issue-81059, r=jackh726
Suggest making binding `mut` on `&mut` reborrow
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.
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Aug 17, 2026
Rollup of 7 pull requests
Successful merges:
- rust-lang/rust#147141 (Suggest making binding `mut` on `&mut` reborrow)
- rust-lang/rust#147945 (Port `cfg!()` macro to the new attribute parsing system )
- rust-lang/rust#147951 (Add check for `+=` typo in let chains)
- rust-lang/rust#148004 (fix: Only special case single line item attribute suggestions)
- rust-lang/rust#148264 (reflect that type and const parameter can be intermixed)
- rust-lang/rust#148363 (Fix `wasm_import_module` attribute cross-crate)
- rust-lang/rust#148447 (Tweak E0401)
r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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.

5 participants

@estebank@rustbot@bors@BoxyUwU@jackh726