Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest removing &mut from borrow of &mut
Fix a typo: minding -> binding Add test for &mut &mut
- Loading branch information
Showing
4 changed files
with
60 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
// Suggest not mutably borrowing a mutable reference | ||
#![crate_type = "rlib"] | ||
|
||
fn main() { | ||
f(&mut 0) | ||
pub fn f(b: &mut i32) { | ||
g(&mut b); | ||
//~^ ERROR cannot borrow | ||
g(&mut &mut b); | ||
//~^ ERROR cannot borrow | ||
} | ||
|
||
fn f(b: &mut i32) { | ||
g(&mut b) //~ ERROR cannot borrow | ||
} | ||
|
||
fn g(_: &mut i32) {} | ||
pub fn g(_: &mut i32) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable | ||
--> $DIR/mut-borrow-of-mut-ref.rs:8:7 | ||
--> $DIR/mut-borrow-of-mut-ref.rs:5:7 | ||
| | ||
LL | fn f(b: &mut i32) { | ||
| - help: consider changing this to be mutable: `mut b` | ||
LL | g(&mut b) | ||
| ^^^^^^ cannot borrow as mutable | ||
LL | g(&mut b); | ||
| ^^^^^^ | ||
| | | ||
| cannot borrow as mutable | ||
| try removing `&mut` here | ||
|
||
error: aborting due to previous error | ||
error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable | ||
--> $DIR/mut-borrow-of-mut-ref.rs:7:12 | ||
| | ||
LL | g(&mut &mut b); | ||
| ^^^^^^ | ||
| | | ||
| cannot borrow as mutable | ||
| try removing `&mut` here | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0596`. |