-
Notifications
You must be signed in to change notification settings - Fork 14k
Suggest making binding mut on &mut reborrow
#147141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
☔ The latest upstream changes (presumably #142390) made this pull request unmergeable. Please resolve the merge conflicts. |
|
r? compiler |
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) {
|
```
|
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. |
There was a problem hiding this comment.
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".
|
@bors r+ rollup |
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.
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
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.
When a binding needs to be mutably reborrowed multiple times, suggesting removing
&mutwill lead to follow up errors. Instead suggest both making the binding mutable and removing the reborrow.Address #81059.