| error[E0502]: cannot borrow `values` as mutable because it is also borrowed as immutable |
| --> $DIR/mutate-vec-while-iterating.rs:8:13 |
| | |
| LL | for value in &values { |
| | - ------- |
| | | | |
| | | immutable borrow occurs here |
| | _____| immutable borrow later used here |
| | | |
| LL | | if *value == 2 { |
| LL | | values.push(4); |
| | | ^^^^^^^^^^^^^^ mutable borrow occurs here |
| LL | | } |
| LL | | } |
| | |_____- this for loop borrows `values` immutably, preventing mutation within its body |
| | |
| = help: consider using an index-based loop instead, or collecting modifications into a separate collection |
| |
| error[E0499]: cannot borrow `values` as mutable more than once at a time |
| --> $DIR/mutate-vec-while-iterating.rs:18:13 |
| | |
| LL | for value in &mut values { |
| | - ----------- |
| | | | |
| | | first mutable borrow occurs here |
| | _____| first borrow later used here |
| | | |
| LL | | if *value == 2 { |
| LL | | values.push(4); |
| | | ^^^^^^ second mutable borrow occurs here |
| LL | | } |
| LL | | } |
| | |_____- this for loop borrows `values` mutably, preventing mutation within its body |
| | |
| = help: consider using an index-based loop instead, or collecting modifications into a separate collection |
| |
| error: aborting due to 2 previous errors |
| |
| Some errors have detailed explanations: E0499, E0502. |
| For more information about an error, try `rustc --explain E0499`. |