mirror of
https://github.com/rust-lang/rust
synced 2024-11-05 20:45:15 +00:00
157 lines
5.8 KiB
Text
157 lines
5.8 KiB
Text
error[E0382]: use of moved value: `vec`
|
|
--> $DIR/recreating-value-in-loop-condition.rs:6:33
|
|
|
|
|
LL | let vec = vec!["one", "two", "three"];
|
|
| --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait
|
|
LL | while let Some(item) = iter(vec).next() {
|
|
| ----------------------------^^^--------
|
|
| | |
|
|
| | value moved here, in previous iteration of loop
|
|
| inside of this loop
|
|
|
|
|
note: consider changing this parameter type in function `iter` to borrow instead if owning the value isn't necessary
|
|
--> $DIR/recreating-value-in-loop-condition.rs:1:17
|
|
|
|
|
LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> {
|
|
| ---- ^^^^^^ this parameter takes ownership of the value
|
|
| |
|
|
| in this function
|
|
help: consider moving the expression out of the loop so it is only moved once
|
|
|
|
|
LL ~ let mut value = iter(vec);
|
|
LL ~ while let Some(item) = value.next() {
|
|
|
|
|
|
|
error[E0382]: use of moved value: `vec`
|
|
--> $DIR/recreating-value-in-loop-condition.rs:15:31
|
|
|
|
|
LL | let vec = vec!["one", "two", "three"];
|
|
| --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait
|
|
LL | loop {
|
|
| ---- inside of this loop
|
|
LL |
|
|
LL | let Some(item) = iter(vec).next() else {
|
|
| ^^^ value moved here, in previous iteration of loop
|
|
|
|
|
note: consider changing this parameter type in function `iter` to borrow instead if owning the value isn't necessary
|
|
--> $DIR/recreating-value-in-loop-condition.rs:1:17
|
|
|
|
|
LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> {
|
|
| ---- ^^^^^^ this parameter takes ownership of the value
|
|
| |
|
|
| in this function
|
|
help: consider moving the expression out of the loop so it is only moved once
|
|
|
|
|
LL ~ let mut value = iter(vec);
|
|
LL ~ loop {
|
|
LL |
|
|
LL ~ let Some(item) = value.next() else {
|
|
|
|
|
|
|
error[E0382]: use of moved value: `vec`
|
|
--> $DIR/recreating-value-in-loop-condition.rs:25:25
|
|
|
|
|
LL | let vec = vec!["one", "two", "three"];
|
|
| --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait
|
|
LL | loop {
|
|
| ---- inside of this loop
|
|
LL |
|
|
LL | let item = iter(vec).next();
|
|
| ^^^ value moved here, in previous iteration of loop
|
|
|
|
|
note: consider changing this parameter type in function `iter` to borrow instead if owning the value isn't necessary
|
|
--> $DIR/recreating-value-in-loop-condition.rs:1:17
|
|
|
|
|
LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> {
|
|
| ---- ^^^^^^ this parameter takes ownership of the value
|
|
| |
|
|
| in this function
|
|
help: consider moving the expression out of the loop so it is only moved once
|
|
|
|
|
LL ~ let mut value = iter(vec);
|
|
LL ~ loop {
|
|
LL |
|
|
LL ~ let item = value.next();
|
|
|
|
|
help: consider cloning the value if the performance cost is acceptable
|
|
|
|
|
LL | let item = iter(vec.clone()).next();
|
|
| ++++++++
|
|
|
|
error[E0382]: use of moved value: `vec`
|
|
--> $DIR/recreating-value-in-loop-condition.rs:37:34
|
|
|
|
|
LL | let vec = vec!["one", "two", "three"];
|
|
| --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait
|
|
LL | loop {
|
|
| ---- inside of this loop
|
|
LL |
|
|
LL | if let Some(item) = iter(vec).next() {
|
|
| ^^^ value moved here, in previous iteration of loop
|
|
|
|
|
note: consider changing this parameter type in function `iter` to borrow instead if owning the value isn't necessary
|
|
--> $DIR/recreating-value-in-loop-condition.rs:1:17
|
|
|
|
|
LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> {
|
|
| ---- ^^^^^^ this parameter takes ownership of the value
|
|
| |
|
|
| in this function
|
|
help: consider moving the expression out of the loop so it is only moved once
|
|
|
|
|
LL ~ let mut value = iter(vec);
|
|
LL ~ loop {
|
|
LL |
|
|
LL ~ if let Some(item) = value.next() {
|
|
|
|
|
|
|
error[E0382]: use of moved value: `vec`
|
|
--> $DIR/recreating-value-in-loop-condition.rs:50:46
|
|
|
|
|
LL | let vec = vec!["one", "two", "three"];
|
|
| --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait
|
|
LL | loop {
|
|
| ---- inside of this loop
|
|
LL |
|
|
LL | loop {
|
|
| ---- inside of this loop
|
|
LL | loop {
|
|
| ---- inside of this loop
|
|
LL | if let Some(item) = iter(vec).next() {
|
|
| ^^^ value moved here, in previous iteration of loop
|
|
|
|
|
note: consider changing this parameter type in function `iter` to borrow instead if owning the value isn't necessary
|
|
--> $DIR/recreating-value-in-loop-condition.rs:1:17
|
|
|
|
|
LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> {
|
|
| ---- ^^^^^^ this parameter takes ownership of the value
|
|
| |
|
|
| in this function
|
|
note: verify that your loop breaking logic is correct
|
|
--> $DIR/recreating-value-in-loop-condition.rs:52:25
|
|
|
|
|
LL | loop {
|
|
| ----
|
|
LL | let vec = vec!["one", "two", "three"];
|
|
LL | loop {
|
|
| ----
|
|
LL |
|
|
LL | loop {
|
|
| ----
|
|
LL | loop {
|
|
| ----
|
|
...
|
|
LL | break;
|
|
| ^^^^^ this `break` exits the loop at line 49
|
|
help: consider moving the expression out of the loop so it is only moved once
|
|
|
|
|
LL ~ let mut value = iter(vec);
|
|
LL ~ loop {
|
|
LL |
|
|
LL | loop {
|
|
LL | loop {
|
|
LL ~ if let Some(item) = value.next() {
|
|
|
|
|
|
|
error: aborting due to 5 previous errors
|
|
|
|
For more information about this error, try `rustc --explain E0382`.
|