suggest removing unnecessary \&mut as help message
This commit is contained in:
parent
e1d49aaad4
commit
e8238a78df
15 changed files with 47 additions and 37 deletions
|
@ -240,7 +240,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
.unwrap_or(false) =>
|
.unwrap_or(false) =>
|
||||||
{
|
{
|
||||||
err.span_label(span, format!("cannot {ACT}", ACT = act));
|
err.span_label(span, format!("cannot {ACT}", ACT = act));
|
||||||
err.span_label(span, "try removing `&mut` here");
|
err.span_suggestion(
|
||||||
|
span,
|
||||||
|
"try removing `&mut` here",
|
||||||
|
String::new(),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to suggest users use `let mut` for local (user
|
// We want to suggest users use `let mut` for local (user
|
||||||
|
@ -322,7 +327,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
} =>
|
} =>
|
||||||
{
|
{
|
||||||
err.span_label(span, format!("cannot {ACT}", ACT = act));
|
err.span_label(span, format!("cannot {ACT}", ACT = act));
|
||||||
err.span_label(span, "try removing `&mut` here");
|
err.span_suggestion(
|
||||||
|
span,
|
||||||
|
"try removing `&mut` here",
|
||||||
|
String::new(),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaceRef { local, projection: [ProjectionElem::Deref] }
|
PlaceRef { local, projection: [ProjectionElem::Deref] }
|
||||||
|
|
|
@ -3,6 +3,7 @@ fn main() {
|
||||||
match op {
|
match op {
|
||||||
Some(ref v) => { let a = &mut v; },
|
Some(ref v) => { let a = &mut v; },
|
||||||
//~^ ERROR cannot borrow `v` as mutable, as it is not declared as mutable
|
//~^ ERROR cannot borrow `v` as mutable, as it is not declared as mutable
|
||||||
|
//~^ HELP try removing `&mut` here
|
||||||
None => {},
|
None => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ LL | Some(ref v) => { let a = &mut v; },
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
| |
|
| |
|
||||||
| cannot borrow as mutable
|
| cannot borrow as mutable
|
||||||
| try removing `&mut` here
|
| help: try removing `&mut` here
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,10 @@
|
||||||
pub fn f(b: &mut i32) {
|
pub fn f(b: &mut i32) {
|
||||||
g(&mut b);
|
g(&mut b);
|
||||||
//~^ ERROR cannot borrow
|
//~^ ERROR cannot borrow
|
||||||
|
//~| HELP try removing `&mut` here
|
||||||
g(&mut &mut b);
|
g(&mut &mut b);
|
||||||
//~^ ERROR cannot borrow
|
//~^ ERROR cannot borrow
|
||||||
|
//~| HELP try removing `&mut` here
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn g(_: &mut i32) {}
|
pub fn g(_: &mut i32) {}
|
||||||
|
|
|
@ -5,16 +5,16 @@ LL | g(&mut b);
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
| |
|
| |
|
||||||
| cannot borrow as mutable
|
| cannot borrow as mutable
|
||||||
| try removing `&mut` here
|
| help: try removing `&mut` here
|
||||||
|
|
||||||
error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable
|
error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable
|
||||||
--> $DIR/mut-borrow-of-mut-ref.rs:7:12
|
--> $DIR/mut-borrow-of-mut-ref.rs:8:12
|
||||||
|
|
|
|
||||||
LL | g(&mut &mut b);
|
LL | g(&mut &mut b);
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
| |
|
| |
|
||||||
| cannot borrow as mutable
|
| cannot borrow as mutable
|
||||||
| try removing `&mut` here
|
| help: try removing `&mut` here
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,16 @@ struct Struct;
|
||||||
impl Struct {
|
impl Struct {
|
||||||
fn foo(&mut self) {
|
fn foo(&mut self) {
|
||||||
(&mut self).bar(); //~ ERROR cannot borrow
|
(&mut self).bar(); //~ ERROR cannot borrow
|
||||||
|
//~^ HELP try removing `&mut` here
|
||||||
}
|
}
|
||||||
|
|
||||||
// In this case we could keep the suggestion, but to distinguish the
|
// In this case we could keep the suggestion, but to distinguish the
|
||||||
// two cases is pretty hard. It's an obscure case anyway.
|
// two cases is pretty hard. It's an obscure case anyway.
|
||||||
fn bar(self: &mut Self) {
|
fn bar(self: &mut Self) {
|
||||||
//~^ WARN function cannot return without recursing
|
//~^ WARN function cannot return without recursing
|
||||||
|
//~^^ HELP a `loop` may express intention better if this is on purpose
|
||||||
(&mut self).bar(); //~ ERROR cannot borrow
|
(&mut self).bar(); //~ ERROR cannot borrow
|
||||||
|
//~^ HELP try removing `&mut` here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,14 @@ LL | (&mut self).bar();
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
| |
|
| |
|
||||||
| cannot borrow as mutable
|
| cannot borrow as mutable
|
||||||
| try removing `&mut` here
|
| help: try removing `&mut` here
|
||||||
|
|
||||||
warning: function cannot return without recursing
|
warning: function cannot return without recursing
|
||||||
--> $DIR/issue-31424.rs:12:5
|
--> $DIR/issue-31424.rs:13:5
|
||||||
|
|
|
|
||||||
LL | fn bar(self: &mut Self) {
|
LL | fn bar(self: &mut Self) {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
|
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
|
||||||
LL |
|
...
|
||||||
LL | (&mut self).bar();
|
LL | (&mut self).bar();
|
||||||
| ----------------- recursive call site
|
| ----------------- recursive call site
|
||||||
|
|
|
|
||||||
|
@ -20,13 +20,13 @@ LL | (&mut self).bar();
|
||||||
= help: a `loop` may express intention better if this is on purpose
|
= help: a `loop` may express intention better if this is on purpose
|
||||||
|
|
||||||
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
||||||
--> $DIR/issue-31424.rs:14:9
|
--> $DIR/issue-31424.rs:16:9
|
||||||
|
|
|
|
||||||
LL | (&mut self).bar();
|
LL | (&mut self).bar();
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
| |
|
| |
|
||||||
| cannot borrow as mutable
|
| cannot borrow as mutable
|
||||||
| try removing `&mut` here
|
| help: try removing `&mut` here
|
||||||
|
|
||||||
error: aborting due to 2 previous errors; 1 warning emitted
|
error: aborting due to 2 previous errors; 1 warning emitted
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ impl Z {
|
||||||
fn start(&mut self) {
|
fn start(&mut self) {
|
||||||
self.run(&mut self); //~ ERROR cannot borrow
|
self.run(&mut self); //~ ERROR cannot borrow
|
||||||
//~| ERROR cannot borrow
|
//~| ERROR cannot borrow
|
||||||
|
//~| HELP try removing `&mut` here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ LL | self.run(&mut self);
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
| |
|
| |
|
||||||
| cannot borrow as mutable
|
| cannot borrow as mutable
|
||||||
| try removing `&mut` here
|
| help: try removing `&mut` here
|
||||||
|
|
||||||
error[E0502]: cannot borrow `self` as mutable because it is also borrowed as immutable
|
error[E0502]: cannot borrow `self` as mutable because it is also borrowed as immutable
|
||||||
--> $DIR/issue-34126.rs:6:18
|
--> $DIR/issue-34126.rs:6:18
|
||||||
|
|
|
@ -4,4 +4,5 @@ fn main() {
|
||||||
let mut v: Vec<String> = Vec::new();
|
let mut v: Vec<String> = Vec::new();
|
||||||
let ref mut key = v[0];
|
let ref mut key = v[0];
|
||||||
get(&mut key); //~ ERROR cannot borrow
|
get(&mut key); //~ ERROR cannot borrow
|
||||||
|
//~| HELP try removing `&mut` here
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ LL | get(&mut key);
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
| |
|
| |
|
||||||
| cannot borrow as mutable
|
| cannot borrow as mutable
|
||||||
| try removing `&mut` here
|
| help: try removing `&mut` here
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ fn main() {
|
||||||
match x {
|
match x {
|
||||||
TestEnum::Item(ref mut x) => {
|
TestEnum::Item(ref mut x) => {
|
||||||
test(&mut x); //~ ERROR cannot borrow `x` as mutable, as it is not declared as mutable
|
test(&mut x); //~ ERROR cannot borrow `x` as mutable, as it is not declared as mutable
|
||||||
|
//~| HELP try removing `&mut` here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ LL | test(&mut x);
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
| |
|
| |
|
||||||
| cannot borrow as mutable
|
| cannot borrow as mutable
|
||||||
| try removing `&mut` here
|
| help: try removing `&mut` here
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
|
#![allow(unconditional_recursion)]
|
||||||
|
|
||||||
struct Struct;
|
struct Struct;
|
||||||
|
|
||||||
impl Struct {
|
impl Struct {
|
||||||
fn bar(self: &mut Self) {
|
fn bar(self: &mut Self) {
|
||||||
//~^ WARN function cannot return without recursing
|
|
||||||
(&mut self).bar();
|
(&mut self).bar();
|
||||||
//~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable [E0596]
|
//~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable [E0596]
|
||||||
|
//~^^ HELP try removing `&mut` here
|
||||||
}
|
}
|
||||||
|
|
||||||
fn imm(self) {
|
fn imm(self) { //~ HELP consider changing this to be mutable
|
||||||
(&mut self).bar();
|
(&mut self).bar();
|
||||||
//~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable [E0596]
|
//~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable [E0596]
|
||||||
}
|
}
|
||||||
|
@ -25,7 +27,8 @@ impl Struct {
|
||||||
fn mtblref(&mut self) {
|
fn mtblref(&mut self) {
|
||||||
(&mut self).bar();
|
(&mut self).bar();
|
||||||
//~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable [E0596]
|
//~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable [E0596]
|
||||||
|
//~^^ HELP try removing `&mut` here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main () {}
|
fn main() {}
|
||||||
|
|
|
@ -1,26 +1,14 @@
|
||||||
warning: function cannot return without recursing
|
|
||||||
--> $DIR/issue-51191.rs:4:5
|
|
||||||
|
|
|
||||||
LL | fn bar(self: &mut Self) {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
|
|
||||||
LL |
|
|
||||||
LL | (&mut self).bar();
|
|
||||||
| ----------------- recursive call site
|
|
||||||
|
|
|
||||||
= note: `#[warn(unconditional_recursion)]` on by default
|
|
||||||
= help: a `loop` may express intention better if this is on purpose
|
|
||||||
|
|
||||||
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
||||||
--> $DIR/issue-51191.rs:6:9
|
--> $DIR/issue-51191.rs:7:9
|
||||||
|
|
|
|
||||||
LL | (&mut self).bar();
|
LL | (&mut self).bar();
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
| |
|
| |
|
||||||
| cannot borrow as mutable
|
| cannot borrow as mutable
|
||||||
| try removing `&mut` here
|
| help: try removing `&mut` here
|
||||||
|
|
||||||
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
||||||
--> $DIR/issue-51191.rs:11:9
|
--> $DIR/issue-51191.rs:13:9
|
||||||
|
|
|
|
||||||
LL | fn imm(self) {
|
LL | fn imm(self) {
|
||||||
| ---- help: consider changing this to be mutable: `mut self`
|
| ---- help: consider changing this to be mutable: `mut self`
|
||||||
|
@ -28,26 +16,26 @@ LL | (&mut self).bar();
|
||||||
| ^^^^^^^^^^^ cannot borrow as mutable
|
| ^^^^^^^^^^^ cannot borrow as mutable
|
||||||
|
|
||||||
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
||||||
--> $DIR/issue-51191.rs:20:9
|
--> $DIR/issue-51191.rs:22:9
|
||||||
|
|
|
|
||||||
LL | (&mut self).bar();
|
LL | (&mut self).bar();
|
||||||
| ^^^^^^^^^^^ cannot borrow as mutable
|
| ^^^^^^^^^^^ cannot borrow as mutable
|
||||||
|
|
||||||
error[E0596]: cannot borrow data in a `&` reference as mutable
|
error[E0596]: cannot borrow data in a `&` reference as mutable
|
||||||
--> $DIR/issue-51191.rs:20:9
|
--> $DIR/issue-51191.rs:22:9
|
||||||
|
|
|
|
||||||
LL | (&mut self).bar();
|
LL | (&mut self).bar();
|
||||||
| ^^^^^^^^^^^ cannot borrow as mutable
|
| ^^^^^^^^^^^ cannot borrow as mutable
|
||||||
|
|
||||||
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
||||||
--> $DIR/issue-51191.rs:26:9
|
--> $DIR/issue-51191.rs:28:9
|
||||||
|
|
|
|
||||||
LL | (&mut self).bar();
|
LL | (&mut self).bar();
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
| |
|
| |
|
||||||
| cannot borrow as mutable
|
| cannot borrow as mutable
|
||||||
| try removing `&mut` here
|
| help: try removing `&mut` here
|
||||||
|
|
||||||
error: aborting due to 5 previous errors; 1 warning emitted
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0596`.
|
For more information about this error, try `rustc --explain E0596`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue