Skip to content

Commit f216bac

Browse files
committed
Add HELP to test
1 parent 78d29ad commit f216bac

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

tests/ui/moves/recreating-value-in-loop-condition.rs

+6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> {
44
fn foo() {
55
let vec = vec!["one", "two", "three"];
66
while let Some(item) = iter(vec).next() { //~ ERROR use of moved value
7+
//~^ HELP consider moving the expression out of the loop so it is only moved once
78
println!("{:?}", item);
89
}
910
}
1011
fn bar() {
1112
let vec = vec!["one", "two", "three"];
1213
loop {
14+
//~^ HELP consider moving the expression out of the loop so it is only moved once
1315
let Some(item) = iter(vec).next() else { //~ ERROR use of moved value
1416
break;
1517
};
@@ -19,7 +21,9 @@ fn bar() {
1921
fn baz() {
2022
let vec = vec!["one", "two", "three"];
2123
loop {
24+
//~^ HELP consider moving the expression out of the loop so it is only moved once
2225
let item = iter(vec).next(); //~ ERROR use of moved value
26+
//~^ HELP consider cloning
2327
if item.is_none() {
2428
break;
2529
}
@@ -29,6 +33,7 @@ fn baz() {
2933
fn qux() {
3034
let vec = vec!["one", "two", "three"];
3135
loop {
36+
//~^ HELP consider moving the expression out of the loop so it is only moved once
3237
if let Some(item) = iter(vec).next() { //~ ERROR use of moved value
3338
println!("{:?}", item);
3439
break;
@@ -39,6 +44,7 @@ fn zap() {
3944
loop {
4045
let vec = vec!["one", "two", "three"];
4146
loop {
47+
//~^ HELP consider moving the expression out of the loop so it is only moved once
4248
loop {
4349
loop {
4450
if let Some(item) = iter(vec).next() { //~ ERROR use of moved value

tests/ui/moves/recreating-value-in-loop-condition.stderr

+15-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ LL ~ while let Some(item) = value.next() {
2323
|
2424

2525
error[E0382]: use of moved value: `vec`
26-
--> $DIR/recreating-value-in-loop-condition.rs:13:31
26+
--> $DIR/recreating-value-in-loop-condition.rs:15:31
2727
|
2828
LL | let vec = vec!["one", "two", "three"];
2929
| --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait
3030
LL | loop {
3131
| ---- inside of this loop
32+
LL |
3233
LL | let Some(item) = iter(vec).next() else {
3334
| ^^^ value moved here, in previous iteration of loop
3435
|
@@ -43,16 +44,18 @@ help: consider moving the expression out of the loop so it is only moved once
4344
|
4445
LL ~ let mut value = iter(vec);
4546
LL ~ loop {
47+
LL |
4648
LL ~ let Some(item) = value.next() else {
4749
|
4850

4951
error[E0382]: use of moved value: `vec`
50-
--> $DIR/recreating-value-in-loop-condition.rs:22:25
52+
--> $DIR/recreating-value-in-loop-condition.rs:25:25
5153
|
5254
LL | let vec = vec!["one", "two", "three"];
5355
| --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait
5456
LL | loop {
5557
| ---- inside of this loop
58+
LL |
5659
LL | let item = iter(vec).next();
5760
| ^^^ value moved here, in previous iteration of loop
5861
|
@@ -67,6 +70,7 @@ help: consider moving the expression out of the loop so it is only moved once
6770
|
6871
LL ~ let mut value = iter(vec);
6972
LL ~ loop {
73+
LL |
7074
LL ~ let item = value.next();
7175
|
7276
help: consider cloning the value if the performance cost is acceptable
@@ -75,12 +79,13 @@ LL | let item = iter(vec.clone()).next();
7579
| ++++++++
7680

7781
error[E0382]: use of moved value: `vec`
78-
--> $DIR/recreating-value-in-loop-condition.rs:32:34
82+
--> $DIR/recreating-value-in-loop-condition.rs:37:34
7983
|
8084
LL | let vec = vec!["one", "two", "three"];
8185
| --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait
8286
LL | loop {
8387
| ---- inside of this loop
88+
LL |
8489
LL | if let Some(item) = iter(vec).next() {
8590
| ^^^ value moved here, in previous iteration of loop
8691
|
@@ -95,16 +100,18 @@ help: consider moving the expression out of the loop so it is only moved once
95100
|
96101
LL ~ let mut value = iter(vec);
97102
LL ~ loop {
103+
LL |
98104
LL ~ if let Some(item) = value.next() {
99105
|
100106

101107
error[E0382]: use of moved value: `vec`
102-
--> $DIR/recreating-value-in-loop-condition.rs:44:46
108+
--> $DIR/recreating-value-in-loop-condition.rs:50:46
103109
|
104110
LL | let vec = vec!["one", "two", "three"];
105111
| --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait
106112
LL | loop {
107113
| ---- inside of this loop
114+
LL |
108115
LL | loop {
109116
| ---- inside of this loop
110117
LL | loop {
@@ -120,24 +127,26 @@ LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> {
120127
| |
121128
| in this function
122129
note: verify that your loop breaking logic is correct
123-
--> $DIR/recreating-value-in-loop-condition.rs:46:25
130+
--> $DIR/recreating-value-in-loop-condition.rs:52:25
124131
|
125132
LL | loop {
126133
| ----
127134
LL | let vec = vec!["one", "two", "three"];
128135
LL | loop {
129136
| ----
137+
LL |
130138
LL | loop {
131139
| ----
132140
LL | loop {
133141
| ----
134142
...
135143
LL | break;
136-
| ^^^^^ this `break` exits the loop at line 43
144+
| ^^^^^ this `break` exits the loop at line 49
137145
help: consider moving the expression out of the loop so it is only moved once
138146
|
139147
LL ~ let mut value = iter(vec);
140148
LL ~ loop {
149+
LL |
141150
LL | loop {
142151
LL | loop {
143152
LL ~ if let Some(item) = value.next() {

0 commit comments

Comments
 (0)