mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
42 lines
853 B
Rust
42 lines
853 B
Rust
//@ run-rustfix
|
|
|
|
fn test1() {
|
|
let mut chars = "Hello".chars();
|
|
let iter = chars.by_ref();
|
|
while let Some(_c) = iter.next() {
|
|
iter.next(); //~ ERROR cannot borrow `chars` as mutable more than once at a time
|
|
}
|
|
}
|
|
|
|
fn test2() {
|
|
let v = vec![1, 2, 3];
|
|
let mut iter = v.iter();
|
|
while let Some(_i) = iter.next() {
|
|
iter.next(); //~ ERROR borrow of moved value: `iter`
|
|
}
|
|
}
|
|
|
|
fn test3() {
|
|
let v = vec![(), (), ()];
|
|
let mut i = v.iter();
|
|
let iter = i.by_ref();
|
|
while let Some(()) = iter.next() {
|
|
iter.next(); //~ ERROR cannot borrow `i`
|
|
}
|
|
}
|
|
|
|
fn test4() {
|
|
let v = vec![(), (), ()];
|
|
let mut iter = v.iter();
|
|
while let Some(()) = iter.next() {
|
|
iter.next(); //~ ERROR borrow of moved value: `iter`
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
test1();
|
|
test2();
|
|
test3();
|
|
test4();
|
|
}
|