Update test to show incorrecct +=
clone suggestion
This commit is contained in:
parent
a1a3abb08f
commit
b83ebea5de
2 changed files with 9 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
use std::ops::AddAssign;
|
use std::ops::AddAssign;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
struct Int(i32);
|
struct Int(i32);
|
||||||
|
|
||||||
impl AddAssign for Int {
|
impl AddAssign for Int {
|
||||||
|
@ -12,6 +13,7 @@ fn main() {
|
||||||
let mut x = Int(1); //~ NOTE binding `x` declared here
|
let mut x = Int(1); //~ NOTE binding `x` declared here
|
||||||
x
|
x
|
||||||
//~^ NOTE borrow of `x` occurs here
|
//~^ NOTE borrow of `x` occurs here
|
||||||
|
//~| HELP consider cloning
|
||||||
+=
|
+=
|
||||||
x;
|
x;
|
||||||
//~^ ERROR cannot move out of `x` because it is borrowed
|
//~^ ERROR cannot move out of `x` because it is borrowed
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0505]: cannot move out of `x` because it is borrowed
|
error[E0505]: cannot move out of `x` because it is borrowed
|
||||||
--> $DIR/augmented-assignments.rs:16:5
|
--> $DIR/augmented-assignments.rs:17:5
|
||||||
|
|
|
|
||||||
LL | let mut x = Int(1);
|
LL | let mut x = Int(1);
|
||||||
| ----- binding `x` declared here
|
| ----- binding `x` declared here
|
||||||
|
@ -8,9 +8,14 @@ LL | x
|
||||||
...
|
...
|
||||||
LL | x;
|
LL | x;
|
||||||
| ^ move out of `x` occurs here
|
| ^ move out of `x` occurs here
|
||||||
|
|
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL | x.clone()
|
||||||
|
| ++++++++
|
||||||
|
|
||||||
error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable
|
error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable
|
||||||
--> $DIR/augmented-assignments.rs:23:5
|
--> $DIR/augmented-assignments.rs:25:5
|
||||||
|
|
|
|
||||||
LL | y
|
LL | y
|
||||||
| ^ cannot borrow as mutable
|
| ^ cannot borrow as mutable
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue