2019-03-14 18:09:47 -05:00
|
|
|
error[E0505]: cannot move out of `a` because it is borrowed
|
|
|
|
--> $DIR/borrow-for-loop-head.rs:4:18
|
|
|
|
|
|
2023-01-14 21:06:44 -06:00
|
|
|
LL | let a = vec![1, 2, 3];
|
|
|
|
| - binding `a` declared here
|
2019-03-14 18:09:47 -05:00
|
|
|
LL | for i in &a {
|
2019-04-22 02:40:08 -05:00
|
|
|
| -- borrow of `a` occurs here
|
2019-03-14 18:09:47 -05:00
|
|
|
LL | for j in a {
|
|
|
|
| ^ move out of `a` occurs here
|
|
|
|
|
|
|
|
error[E0382]: use of moved value: `a`
|
|
|
|
--> $DIR/borrow-for-loop-head.rs:4:18
|
|
|
|
|
|
2019-04-22 02:40:08 -05:00
|
|
|
LL | let a = vec![1, 2, 3];
|
2020-09-02 02:40:56 -05:00
|
|
|
| - move occurs because `a` has type `Vec<i32>`, which does not implement the `Copy` trait
|
2019-04-22 02:40:08 -05:00
|
|
|
LL | for i in &a {
|
2022-11-02 23:22:24 -05:00
|
|
|
| ----------- inside of this loop
|
2019-03-14 18:09:47 -05:00
|
|
|
LL | for j in a {
|
2022-03-01 22:30:16 -06:00
|
|
|
| ^ `a` moved due to this implicit call to `.into_iter()`, in previous iteration of loop
|
2020-12-22 21:15:40 -06:00
|
|
|
|
|
2022-12-12 06:07:09 -06:00
|
|
|
note: `into_iter` takes ownership of the receiver `self`, which moves `a`
|
2020-12-22 21:15:40 -06:00
|
|
|
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
|
2022-03-01 22:30:16 -06:00
|
|
|
help: consider iterating over a slice of the `Vec<i32>`'s content to avoid moving into the `for` loop
|
|
|
|
|
|
|
|
|
LL | for j in &a {
|
|
|
|
| +
|
2019-03-14 18:09:47 -05:00
|
|
|
|
|
|
|
error: aborting due to 2 previous errors
|
|
|
|
|
2019-04-17 12:26:38 -05:00
|
|
|
Some errors have detailed explanations: E0382, E0505.
|
2019-03-14 18:09:47 -05:00
|
|
|
For more information about an error, try `rustc --explain E0382`.
|