This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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`.
You can’t perform that action at this time.
0 commit comments