Skip to content

Commit b83ebea

Browse files
committed
Update test to show incorrecct += clone suggestion
1 parent a1a3abb commit b83ebea

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

tests/ui/augmented-assignments.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::ops::AddAssign;
22

3+
#[derive(Clone)]
34
struct Int(i32);
45

56
impl AddAssign for Int {
@@ -12,6 +13,7 @@ fn main() {
1213
let mut x = Int(1); //~ NOTE binding `x` declared here
1314
x
1415
//~^ NOTE borrow of `x` occurs here
16+
//~| HELP consider cloning
1517
+=
1618
x;
1719
//~^ ERROR cannot move out of `x` because it is borrowed

tests/ui/augmented-assignments.stderr

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0505]: cannot move out of `x` because it is borrowed
2-
--> $DIR/augmented-assignments.rs:16:5
2+
--> $DIR/augmented-assignments.rs:17:5
33
|
44
LL | let mut x = Int(1);
55
| ----- binding `x` declared here
@@ -8,9 +8,14 @@ LL | x
88
...
99
LL | x;
1010
| ^ move out of `x` occurs here
11+
|
12+
help: consider cloning the value if the performance cost is acceptable
13+
|
14+
LL | x.clone()
15+
| ++++++++
1116

1217
error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable
13-
--> $DIR/augmented-assignments.rs:23:5
18+
--> $DIR/augmented-assignments.rs:25:5
1419
|
1520
LL | y
1621
| ^ cannot borrow as mutable

0 commit comments

Comments
 (0)