Skip to content

Commit a775984

Browse files
committed
Add regression test
1 parent 7f823e5 commit a775984

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

src/test/ui/issues/issue-83924.fixed

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-rustfix
2+
3+
fn main() {
4+
let mut values = vec![10, 11, 12];
5+
let v = &mut values;
6+
7+
let mut max = 0;
8+
9+
for n in &mut *v {
10+
max = std::cmp::max(max, *n);
11+
}
12+
13+
println!("max is {}", max);
14+
println!("Converting to percentages of maximum value...");
15+
for n in v {
16+
//~^ ERROR: use of moved value: `v` [E0382]
17+
*n = 100 * (*n) / max;
18+
}
19+
println!("values: {:#?}", values);
20+
}

src/test/ui/issues/issue-83924.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-rustfix
2+
3+
fn main() {
4+
let mut values = vec![10, 11, 12];
5+
let v = &mut values;
6+
7+
let mut max = 0;
8+
9+
for n in v {
10+
max = std::cmp::max(max, *n);
11+
}
12+
13+
println!("max is {}", max);
14+
println!("Converting to percentages of maximum value...");
15+
for n in v {
16+
//~^ ERROR: use of moved value: `v` [E0382]
17+
*n = 100 * (*n) / max;
18+
}
19+
println!("values: {:#?}", values);
20+
}

src/test/ui/issues/issue-83924.stderr

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0382]: use of moved value: `v`
2+
--> $DIR/issue-83924.rs:15:14
3+
|
4+
LL | let v = &mut values;
5+
| - move occurs because `v` has type `&mut Vec<i32>`, which does not implement the `Copy` trait
6+
...
7+
LL | for n in v {
8+
| - `v` moved due to this implicit call to `.into_iter()`
9+
...
10+
LL | for n in v {
11+
| ^ value used here after move
12+
|
13+
note: this function takes ownership of the receiver `self`, which moves `v`
14+
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
15+
|
16+
LL | fn into_iter(self) -> Self::IntoIter;
17+
| ^^^^
18+
help: consider creating a fresh reborrow of `v` here
19+
|
20+
LL | for n in &mut *v {
21+
| ^^^^^^
22+
23+
error: aborting due to previous error
24+
25+
For more information about this error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)