Add HELP to test

This commit is contained in:
Esteban Küber 2024-03-17 21:45:03 +00:00
parent 78d29ad8d6
commit f216bac861
2 changed files with 21 additions and 6 deletions

View file

@ -4,12 +4,14 @@ fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> {
fn foo() {
let vec = vec!["one", "two", "three"];
while let Some(item) = iter(vec).next() { //~ ERROR use of moved value
//~^ HELP consider moving the expression out of the loop so it is only moved once
println!("{:?}", item);
}
}
fn bar() {
let vec = vec!["one", "two", "three"];
loop {
//~^ HELP consider moving the expression out of the loop so it is only moved once
let Some(item) = iter(vec).next() else { //~ ERROR use of moved value
break;
};
@ -19,7 +21,9 @@ fn bar() {
fn baz() {
let vec = vec!["one", "two", "three"];
loop {
//~^ HELP consider moving the expression out of the loop so it is only moved once
let item = iter(vec).next(); //~ ERROR use of moved value
//~^ HELP consider cloning
if item.is_none() {
break;
}
@ -29,6 +33,7 @@ fn baz() {
fn qux() {
let vec = vec!["one", "two", "three"];
loop {
//~^ HELP consider moving the expression out of the loop so it is only moved once
if let Some(item) = iter(vec).next() { //~ ERROR use of moved value
println!("{:?}", item);
break;
@ -39,6 +44,7 @@ fn zap() {
loop {
let vec = vec!["one", "two", "three"];
loop {
//~^ HELP consider moving the expression out of the loop so it is only moved once
loop {
loop {
if let Some(item) = iter(vec).next() { //~ ERROR use of moved value

View file

@ -23,12 +23,13 @@ LL ~ while let Some(item) = value.next() {
|
error[E0382]: use of moved value: `vec`
--> $DIR/recreating-value-in-loop-condition.rs:13:31
--> $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
|
@ -43,16 +44,18 @@ 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:22:25
--> $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
|
@ -67,6 +70,7 @@ 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
@ -75,12 +79,13 @@ LL | let item = iter(vec.clone()).next();
| ++++++++
error[E0382]: use of moved value: `vec`
--> $DIR/recreating-value-in-loop-condition.rs:32:34
--> $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
|
@ -95,16 +100,18 @@ 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:44:46
--> $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 {
@ -120,24 +127,26 @@ LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> {
| |
| in this function
note: verify that your loop breaking logic is correct
--> $DIR/recreating-value-in-loop-condition.rs:46:25
--> $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 43
| ^^^^^ 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() {