From f216bac8618e6387cdc9cd25791347fc93889147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 17 Mar 2024 21:45:03 +0000 Subject: [PATCH] Add `HELP` to test --- .../recreating-value-in-loop-condition.rs | 6 ++++++ .../recreating-value-in-loop-condition.stderr | 21 +++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/ui/moves/recreating-value-in-loop-condition.rs b/tests/ui/moves/recreating-value-in-loop-condition.rs index 000a8471e86..ad012ff2978 100644 --- a/tests/ui/moves/recreating-value-in-loop-condition.rs +++ b/tests/ui/moves/recreating-value-in-loop-condition.rs @@ -4,12 +4,14 @@ fn iter(vec: Vec) -> impl Iterator { 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 diff --git a/tests/ui/moves/recreating-value-in-loop-condition.stderr b/tests/ui/moves/recreating-value-in-loop-condition.stderr index fbf76c780d7..75c9633bc0a 100644 --- a/tests/ui/moves/recreating-value-in-loop-condition.stderr +++ b/tests/ui/moves/recreating-value-in-loop-condition.stderr @@ -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(vec: Vec) -> impl Iterator { | | | 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() {