diff options
Diffstat (limited to 'tests')
8 files changed, 95 insertions, 22 deletions
diff --git a/tests/ui/liveness/liveness-move-call-arg-2.stderr b/tests/ui/liveness/liveness-move-call-arg-2.stderr index 9b036541e8d..f4252e1ac33 100644 --- a/tests/ui/liveness/liveness-move-call-arg-2.stderr +++ b/tests/ui/liveness/liveness-move-call-arg-2.stderr @@ -16,12 +16,6 @@ LL | fn take(_x: Box<isize>) {} | ---- ^^^^^^^^^^ this parameter takes ownership of the value | | | in this function -help: consider moving the expression out of the loop so it is only moved once - | -LL ~ let mut value = take(x); -LL ~ loop { -LL ~ value; - | help: consider cloning the value if the performance cost is acceptable | LL | take(x.clone()); diff --git a/tests/ui/liveness/liveness-move-call-arg.stderr b/tests/ui/liveness/liveness-move-call-arg.stderr index b1d831b9ef9..9697ed5cb11 100644 --- a/tests/ui/liveness/liveness-move-call-arg.stderr +++ b/tests/ui/liveness/liveness-move-call-arg.stderr @@ -16,12 +16,6 @@ LL | fn take(_x: Box<isize>) {} | ---- ^^^^^^^^^^ this parameter takes ownership of the value | | | in this function -help: consider moving the expression out of the loop so it is only moved once - | -LL ~ let mut value = take(x); -LL ~ loop { -LL ~ value; - | help: consider cloning the value if the performance cost is acceptable | LL | take(x.clone()); diff --git a/tests/ui/moves/borrow-closures-instead-of-move.rs b/tests/ui/moves/borrow-closures-instead-of-move.rs index ab8a2802213..51771ced7f2 100644 --- a/tests/ui/moves/borrow-closures-instead-of-move.rs +++ b/tests/ui/moves/borrow-closures-instead-of-move.rs @@ -1,5 +1,5 @@ fn takes_fn(f: impl Fn()) { - loop { //~ HELP consider moving the expression out of the loop so it is only computed once + loop { takes_fnonce(f); //~^ ERROR use of moved value //~| HELP consider borrowing diff --git a/tests/ui/moves/borrow-closures-instead-of-move.stderr b/tests/ui/moves/borrow-closures-instead-of-move.stderr index b2787fd5c72..9a84ddef7e6 100644 --- a/tests/ui/moves/borrow-closures-instead-of-move.stderr +++ b/tests/ui/moves/borrow-closures-instead-of-move.stderr @@ -15,12 +15,6 @@ LL | fn takes_fnonce(_: impl FnOnce()) {} | ------------ ^^^^^^^^^^^^^ this parameter takes ownership of the value | | | in this function -help: consider moving the expression out of the loop so it is only moved once - | -LL ~ let mut value = takes_fnonce(f); -LL ~ loop { -LL ~ value; - | help: consider borrowing `f` | LL | takes_fnonce(&f); diff --git a/tests/ui/moves/nested-loop-moved-value-wrong-continue.rs b/tests/ui/moves/nested-loop-moved-value-wrong-continue.rs index 618d820a2ab..0235b291df5 100644 --- a/tests/ui/moves/nested-loop-moved-value-wrong-continue.rs +++ b/tests/ui/moves/nested-loop-moved-value-wrong-continue.rs @@ -1,3 +1,27 @@ +fn foo() { + let foos = vec![String::new()]; + let bars = vec![""]; + let mut baz = vec![]; + let mut qux = vec![]; + for foo in foos { for bar in &bars { if foo == *bar { + //~^ NOTE this reinitialization might get skipped + //~| NOTE move occurs because `foo` has type `String` + //~| NOTE inside of this loop + //~| HELP consider moving the expression out of the loop + //~| NOTE in this expansion of desugaring of `for` loop + baz.push(foo); + //~^ NOTE value moved here + //~| HELP consider cloning the value + continue; + //~^ NOTE verify that your loop breaking logic is correct + //~| NOTE this `continue` advances the loop at $DIR/nested-loop-moved-value-wrong-continue.rs:6:23 + } } + qux.push(foo); + //~^ ERROR use of moved value + //~| NOTE value used here + } +} + fn main() { let foos = vec![String::new()]; let bars = vec![""]; @@ -15,6 +39,8 @@ fn main() { //~^ NOTE value moved here //~| HELP consider cloning the value continue; + //~^ NOTE verify that your loop breaking logic is correct + //~| NOTE this `continue` advances the loop at line 33 } } qux.push(foo); diff --git a/tests/ui/moves/nested-loop-moved-value-wrong-continue.stderr b/tests/ui/moves/nested-loop-moved-value-wrong-continue.stderr index f04b5ecb935..3247513d42c 100644 --- a/tests/ui/moves/nested-loop-moved-value-wrong-continue.stderr +++ b/tests/ui/moves/nested-loop-moved-value-wrong-continue.stderr @@ -1,5 +1,42 @@ error[E0382]: use of moved value: `foo` - --> $DIR/nested-loop-moved-value-wrong-continue.rs:20:18 + --> $DIR/nested-loop-moved-value-wrong-continue.rs:19:14 + | +LL | for foo in foos { for bar in &bars { if foo == *bar { + | --- ---------------- inside of this loop + | | + | this reinitialization might get skipped + | move occurs because `foo` has type `String`, which does not implement the `Copy` trait +... +LL | baz.push(foo); + | --- value moved here, in previous iteration of loop +... +LL | qux.push(foo); + | ^^^ value used here after move + | +note: verify that your loop breaking logic is correct + --> $DIR/nested-loop-moved-value-wrong-continue.rs:15:9 + | +LL | for foo in foos { for bar in &bars { if foo == *bar { + | --------------- ---------------- +... +LL | continue; + | ^^^^^^^^ this `continue` advances the loop at $DIR/nested-loop-moved-value-wrong-continue.rs:6:23: 18:8 +help: consider moving the expression out of the loop so it is only moved once + | +LL ~ for foo in foos { let mut value = baz.push(foo); +LL ~ for bar in &bars { if foo == *bar { +LL | + ... +LL | +LL ~ value; + | +help: consider cloning the value if the performance cost is acceptable + | +LL | baz.push(foo.clone()); + | ++++++++ + +error[E0382]: use of moved value: `foo` + --> $DIR/nested-loop-moved-value-wrong-continue.rs:46:18 | LL | for foo in foos { | --- @@ -16,6 +53,17 @@ LL | baz.push(foo); LL | qux.push(foo); | ^^^ value used here after move | +note: verify that your loop breaking logic is correct + --> $DIR/nested-loop-moved-value-wrong-continue.rs:41:17 + | +LL | for foo in foos { + | --------------- +... +LL | for bar in &bars { + | ---------------- +... +LL | continue; + | ^^^^^^^^ this `continue` advances the loop at line 33 help: consider moving the expression out of the loop so it is only moved once | LL ~ let mut value = baz.push(foo); @@ -30,6 +78,6 @@ help: consider cloning the value if the performance cost is acceptable LL | baz.push(foo.clone()); | ++++++++ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/recreating-value-in-loop-condition.rs b/tests/ui/moves/recreating-value-in-loop-condition.rs index 03df8102410..000a8471e86 100644 --- a/tests/ui/moves/recreating-value-in-loop-condition.rs +++ b/tests/ui/moves/recreating-value-in-loop-condition.rs @@ -31,6 +31,7 @@ fn qux() { loop { if let Some(item) = iter(vec).next() { //~ ERROR use of moved value println!("{:?}", item); + break; } } } @@ -42,6 +43,7 @@ fn zap() { loop { if let Some(item) = iter(vec).next() { //~ ERROR use of moved value println!("{:?}", item); + break; } } } diff --git a/tests/ui/moves/recreating-value-in-loop-condition.stderr b/tests/ui/moves/recreating-value-in-loop-condition.stderr index ee2a68b72c1..fbf76c780d7 100644 --- a/tests/ui/moves/recreating-value-in-loop-condition.stderr +++ b/tests/ui/moves/recreating-value-in-loop-condition.stderr @@ -99,7 +99,7 @@ LL ~ if let Some(item) = value.next() { | error[E0382]: use of moved value: `vec` - --> $DIR/recreating-value-in-loop-condition.rs:43:46 + --> $DIR/recreating-value-in-loop-condition.rs:44:46 | LL | let vec = vec!["one", "two", "three"]; | --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait @@ -119,6 +119,21 @@ LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> { | ---- ^^^^^^ this parameter takes ownership of the value | | | in this function +note: verify that your loop breaking logic is correct + --> $DIR/recreating-value-in-loop-condition.rs:46:25 + | +LL | loop { + | ---- +LL | let vec = vec!["one", "two", "three"]; +LL | loop { + | ---- +LL | loop { + | ---- +LL | loop { + | ---- +... +LL | break; + | ^^^^^ this `break` exits the loop at line 43 help: consider moving the expression out of the loop so it is only moved once | LL ~ let mut value = iter(vec); |
