2024-02-26 14:06:19 -06:00
|
|
|
fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> {
|
|
|
|
vec.into_iter()
|
|
|
|
}
|
|
|
|
fn foo() {
|
|
|
|
let vec = vec!["one", "two", "three"];
|
|
|
|
while let Some(item) = iter(vec).next() { //~ ERROR use of moved value
|
2024-03-17 16:45:03 -05:00
|
|
|
//~^ HELP consider moving the expression out of the loop so it is only moved once
|
2024-02-26 14:06:19 -06:00
|
|
|
println!("{:?}", item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn bar() {
|
|
|
|
let vec = vec!["one", "two", "three"];
|
|
|
|
loop {
|
2024-03-17 16:45:03 -05:00
|
|
|
//~^ HELP consider moving the expression out of the loop so it is only moved once
|
2024-02-26 14:06:19 -06:00
|
|
|
let Some(item) = iter(vec).next() else { //~ ERROR use of moved value
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
println!("{:?}", item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn baz() {
|
|
|
|
let vec = vec!["one", "two", "three"];
|
|
|
|
loop {
|
2024-03-17 16:45:03 -05:00
|
|
|
//~^ HELP consider moving the expression out of the loop so it is only moved once
|
2024-02-26 14:06:19 -06:00
|
|
|
let item = iter(vec).next(); //~ ERROR use of moved value
|
2024-03-17 16:45:03 -05:00
|
|
|
//~^ HELP consider cloning
|
2024-02-26 14:06:19 -06:00
|
|
|
if item.is_none() {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
println!("{:?}", item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn qux() {
|
|
|
|
let vec = vec!["one", "two", "three"];
|
|
|
|
loop {
|
2024-03-17 16:45:03 -05:00
|
|
|
//~^ HELP consider moving the expression out of the loop so it is only moved once
|
2024-02-26 14:06:19 -06:00
|
|
|
if let Some(item) = iter(vec).next() { //~ ERROR use of moved value
|
|
|
|
println!("{:?}", item);
|
2024-02-26 16:54:34 -06:00
|
|
|
break;
|
2024-02-26 14:06:19 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn zap() {
|
|
|
|
loop {
|
|
|
|
let vec = vec!["one", "two", "three"];
|
|
|
|
loop {
|
2024-03-17 16:45:03 -05:00
|
|
|
//~^ HELP consider moving the expression out of the loop so it is only moved once
|
2024-02-26 14:06:19 -06:00
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
if let Some(item) = iter(vec).next() { //~ ERROR use of moved value
|
|
|
|
println!("{:?}", item);
|
2024-02-26 16:54:34 -06:00
|
|
|
break;
|
2024-02-26 14:06:19 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn main() {
|
|
|
|
foo();
|
|
|
|
bar();
|
|
|
|
baz();
|
|
|
|
qux();
|
|
|
|
zap();
|
|
|
|
}
|