Skip to content

Commit bcf0805

Browse files
committed
Auto merge of #4022 - phansch:move_some_loop_tests, r=flip1995
UI test cleanup: Extract needless_range_loop tests changelog: none
2 parents 253601a + 0fbe49d commit bcf0805

File tree

4 files changed

+234
-228
lines changed

4 files changed

+234
-228
lines changed

tests/ui/for_loop.rs

-63
Original file line numberDiff line numberDiff line change
@@ -35,70 +35,7 @@ impl Unrelated {
3535
#[allow(clippy::many_single_char_names, unused_variables, clippy::into_iter_on_array)]
3636
fn main() {
3737
const MAX_LEN: usize = 42;
38-
3938
let mut vec = vec![1, 2, 3, 4];
40-
let vec2 = vec![1, 2, 3, 4];
41-
for i in 0..vec.len() {
42-
println!("{}", vec[i]);
43-
}
44-
45-
for i in 0..vec.len() {
46-
let i = 42; // make a different `i`
47-
println!("{}", vec[i]); // ok, not the `i` of the for-loop
48-
}
49-
50-
for i in 0..vec.len() {
51-
let _ = vec[i];
52-
}
53-
54-
// ICE #746
55-
for j in 0..4 {
56-
println!("{:?}", STATIC[j]);
57-
}
58-
59-
for j in 0..4 {
60-
println!("{:?}", CONST[j]);
61-
}
62-
63-
for i in 0..vec.len() {
64-
println!("{} {}", vec[i], i);
65-
}
66-
for i in 0..vec.len() {
67-
// not an error, indexing more than one variable
68-
println!("{} {}", vec[i], vec2[i]);
69-
}
70-
71-
for i in 0..vec.len() {
72-
println!("{}", vec2[i]);
73-
}
74-
75-
for i in 5..vec.len() {
76-
println!("{}", vec[i]);
77-
}
78-
79-
for i in 0..MAX_LEN {
80-
println!("{}", vec[i]);
81-
}
82-
83-
for i in 0..=MAX_LEN {
84-
println!("{}", vec[i]);
85-
}
86-
87-
for i in 5..10 {
88-
println!("{}", vec[i]);
89-
}
90-
91-
for i in 5..=10 {
92-
println!("{}", vec[i]);
93-
}
94-
95-
for i in 5..vec.len() {
96-
println!("{} {}", vec[i], i);
97-
}
98-
99-
for i in 5..10 {
100-
println!("{} {}", vec[i], i);
101-
}
10239

10340
for i in 10..0 {
10441
println!("{}", i);

tests/ui/for_loop.stderr

+23-155
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,5 @@
1-
error: the loop variable `i` is only used to index `vec`.
2-
--> $DIR/for_loop.rs:41:14
3-
|
4-
LL | for i in 0..vec.len() {
5-
| ^^^^^^^^^^^^
6-
|
7-
= note: `-D clippy::needless-range-loop` implied by `-D warnings`
8-
help: consider using an iterator
9-
|
10-
LL | for <item> in &vec {
11-
| ^^^^^^ ^^^^
12-
13-
error: the loop variable `i` is only used to index `vec`.
14-
--> $DIR/for_loop.rs:50:14
15-
|
16-
LL | for i in 0..vec.len() {
17-
| ^^^^^^^^^^^^
18-
help: consider using an iterator
19-
|
20-
LL | for <item> in &vec {
21-
| ^^^^^^ ^^^^
22-
23-
error: the loop variable `j` is only used to index `STATIC`.
24-
--> $DIR/for_loop.rs:55:14
25-
|
26-
LL | for j in 0..4 {
27-
| ^^^^
28-
help: consider using an iterator
29-
|
30-
LL | for <item> in &STATIC {
31-
| ^^^^^^ ^^^^^^^
32-
33-
error: the loop variable `j` is only used to index `CONST`.
34-
--> $DIR/for_loop.rs:59:14
35-
|
36-
LL | for j in 0..4 {
37-
| ^^^^
38-
help: consider using an iterator
39-
|
40-
LL | for <item> in &CONST {
41-
| ^^^^^^ ^^^^^^
42-
43-
error: the loop variable `i` is used to index `vec`
44-
--> $DIR/for_loop.rs:63:14
45-
|
46-
LL | for i in 0..vec.len() {
47-
| ^^^^^^^^^^^^
48-
help: consider using an iterator
49-
|
50-
LL | for (i, <item>) in vec.iter().enumerate() {
51-
| ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
52-
53-
error: the loop variable `i` is only used to index `vec2`.
54-
--> $DIR/for_loop.rs:71:14
55-
|
56-
LL | for i in 0..vec.len() {
57-
| ^^^^^^^^^^^^
58-
help: consider using an iterator
59-
|
60-
LL | for <item> in vec2.iter().take(vec.len()) {
61-
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
62-
63-
error: the loop variable `i` is only used to index `vec`.
64-
--> $DIR/for_loop.rs:75:14
65-
|
66-
LL | for i in 5..vec.len() {
67-
| ^^^^^^^^^^^^
68-
help: consider using an iterator
69-
|
70-
LL | for <item> in vec.iter().skip(5) {
71-
| ^^^^^^ ^^^^^^^^^^^^^^^^^^
72-
73-
error: the loop variable `i` is only used to index `vec`.
74-
--> $DIR/for_loop.rs:79:14
75-
|
76-
LL | for i in 0..MAX_LEN {
77-
| ^^^^^^^^^^
78-
help: consider using an iterator
79-
|
80-
LL | for <item> in vec.iter().take(MAX_LEN) {
81-
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^
82-
83-
error: the loop variable `i` is only used to index `vec`.
84-
--> $DIR/for_loop.rs:83:14
85-
|
86-
LL | for i in 0..=MAX_LEN {
87-
| ^^^^^^^^^^^
88-
help: consider using an iterator
89-
|
90-
LL | for <item> in vec.iter().take(MAX_LEN + 1) {
91-
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
92-
93-
error: the loop variable `i` is only used to index `vec`.
94-
--> $DIR/for_loop.rs:87:14
95-
|
96-
LL | for i in 5..10 {
97-
| ^^^^^
98-
help: consider using an iterator
99-
|
100-
LL | for <item> in vec.iter().take(10).skip(5) {
101-
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
102-
103-
error: the loop variable `i` is only used to index `vec`.
104-
--> $DIR/for_loop.rs:91:14
105-
|
106-
LL | for i in 5..=10 {
107-
| ^^^^^^
108-
help: consider using an iterator
109-
|
110-
LL | for <item> in vec.iter().take(10 + 1).skip(5) {
111-
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
112-
113-
error: the loop variable `i` is used to index `vec`
114-
--> $DIR/for_loop.rs:95:14
115-
|
116-
LL | for i in 5..vec.len() {
117-
| ^^^^^^^^^^^^
118-
help: consider using an iterator
119-
|
120-
LL | for (i, <item>) in vec.iter().enumerate().skip(5) {
121-
| ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
122-
123-
error: the loop variable `i` is used to index `vec`
124-
--> $DIR/for_loop.rs:99:14
125-
|
126-
LL | for i in 5..10 {
127-
| ^^^^^
128-
help: consider using an iterator
129-
|
130-
LL | for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
131-
| ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132-
1331
error: this range is empty so this for loop will never run
134-
--> $DIR/for_loop.rs:103:14
2+
--> $DIR/for_loop.rs:40:14
1353
|
1364
LL | for i in 10..0 {
1375
| ^^^^^
@@ -143,7 +11,7 @@ LL | for i in (0..10).rev() {
14311
| ^^^^^^^^^^^^^
14412

14513
error: this range is empty so this for loop will never run
146-
--> $DIR/for_loop.rs:107:14
14+
--> $DIR/for_loop.rs:44:14
14715
|
14816
LL | for i in 10..=0 {
14917
| ^^^^^^
@@ -153,7 +21,7 @@ LL | for i in (0...10).rev() {
15321
| ^^^^^^^^^^^^^^
15422

15523
error: this range is empty so this for loop will never run
156-
--> $DIR/for_loop.rs:111:14
24+
--> $DIR/for_loop.rs:48:14
15725
|
15826
LL | for i in MAX_LEN..0 {
15927
| ^^^^^^^^^^
@@ -163,13 +31,13 @@ LL | for i in (0..MAX_LEN).rev() {
16331
| ^^^^^^^^^^^^^^^^^^
16432

16533
error: this range is empty so this for loop will never run
166-
--> $DIR/for_loop.rs:115:14
34+
--> $DIR/for_loop.rs:52:14
16735
|
16836
LL | for i in 5..5 {
16937
| ^^^^
17038

17139
error: this range is empty so this for loop will never run
172-
--> $DIR/for_loop.rs:140:14
40+
--> $DIR/for_loop.rs:77:14
17341
|
17442
LL | for i in 10..5 + 4 {
17543
| ^^^^^^^^^
@@ -179,7 +47,7 @@ LL | for i in (5 + 4..10).rev() {
17947
| ^^^^^^^^^^^^^^^^^
18048

18149
error: this range is empty so this for loop will never run
182-
--> $DIR/for_loop.rs:144:14
50+
--> $DIR/for_loop.rs:81:14
18351
|
18452
LL | for i in (5 + 2)..(3 - 1) {
18553
| ^^^^^^^^^^^^^^^^
@@ -189,108 +57,108 @@ LL | for i in ((3 - 1)..(5 + 2)).rev() {
18957
| ^^^^^^^^^^^^^^^^^^^^^^^^
19058

19159
error: this range is empty so this for loop will never run
192-
--> $DIR/for_loop.rs:148:14
60+
--> $DIR/for_loop.rs:85:14
19361
|
19462
LL | for i in (5 + 2)..(8 - 1) {
19563
| ^^^^^^^^^^^^^^^^
19664

19765
error: it is more concise to loop over references to containers instead of using explicit iteration methods
198-
--> $DIR/for_loop.rs:170:15
66+
--> $DIR/for_loop.rs:107:15
19967
|
20068
LL | for _v in vec.iter() {}
20169
| ^^^^^^^^^^
20270
|
20371
= note: `-D clippy::explicit-iter-loop` implied by `-D warnings`
20472

20573
error: it is more concise to loop over references to containers instead of using explicit iteration methods
206-
--> $DIR/for_loop.rs:172:15
74+
--> $DIR/for_loop.rs:109:15
20775
|
20876
LL | for _v in vec.iter_mut() {}
20977
| ^^^^^^^^^^^^^^
21078

21179
error: it is more concise to loop over containers instead of using explicit iteration methods`
212-
--> $DIR/for_loop.rs:175:15
80+
--> $DIR/for_loop.rs:112:15
21381
|
21482
LL | for _v in out_vec.into_iter() {}
21583
| ^^^^^^^^^^^^^^^^^^^
21684
|
21785
= note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings`
21886

21987
error: it is more concise to loop over references to containers instead of using explicit iteration methods
220-
--> $DIR/for_loop.rs:178:15
88+
--> $DIR/for_loop.rs:115:15
22189
|
22290
LL | for _v in array.into_iter() {}
22391
| ^^^^^^^^^^^^^^^^^
22492

22593
error: it is more concise to loop over references to containers instead of using explicit iteration methods
226-
--> $DIR/for_loop.rs:183:15
94+
--> $DIR/for_loop.rs:120:15
22795
|
22896
LL | for _v in [1, 2, 3].iter() {}
22997
| ^^^^^^^^^^^^^^^^
23098

23199
error: it is more concise to loop over references to containers instead of using explicit iteration methods
232-
--> $DIR/for_loop.rs:187:15
100+
--> $DIR/for_loop.rs:124:15
233101
|
234102
LL | for _v in [0; 32].iter() {}
235103
| ^^^^^^^^^^^^^^
236104

237105
error: it is more concise to loop over references to containers instead of using explicit iteration methods
238-
--> $DIR/for_loop.rs:192:15
106+
--> $DIR/for_loop.rs:129:15
239107
|
240108
LL | for _v in ll.iter() {}
241109
| ^^^^^^^^^
242110

243111
error: it is more concise to loop over references to containers instead of using explicit iteration methods
244-
--> $DIR/for_loop.rs:195:15
112+
--> $DIR/for_loop.rs:132:15
245113
|
246114
LL | for _v in vd.iter() {}
247115
| ^^^^^^^^^
248116

249117
error: it is more concise to loop over references to containers instead of using explicit iteration methods
250-
--> $DIR/for_loop.rs:198:15
118+
--> $DIR/for_loop.rs:135:15
251119
|
252120
LL | for _v in bh.iter() {}
253121
| ^^^^^^^^^
254122

255123
error: it is more concise to loop over references to containers instead of using explicit iteration methods
256-
--> $DIR/for_loop.rs:201:15
124+
--> $DIR/for_loop.rs:138:15
257125
|
258126
LL | for _v in hm.iter() {}
259127
| ^^^^^^^^^
260128

261129
error: it is more concise to loop over references to containers instead of using explicit iteration methods
262-
--> $DIR/for_loop.rs:204:15
130+
--> $DIR/for_loop.rs:141:15
263131
|
264132
LL | for _v in bt.iter() {}
265133
| ^^^^^^^^^
266134

267135
error: it is more concise to loop over references to containers instead of using explicit iteration methods
268-
--> $DIR/for_loop.rs:207:15
136+
--> $DIR/for_loop.rs:144:15
269137
|
270138
LL | for _v in hs.iter() {}
271139
| ^^^^^^^^^
272140

273141
error: it is more concise to loop over references to containers instead of using explicit iteration methods
274-
--> $DIR/for_loop.rs:210:15
142+
--> $DIR/for_loop.rs:147:15
275143
|
276144
LL | for _v in bs.iter() {}
277145
| ^^^^^^^^^
278146

279147
error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
280-
--> $DIR/for_loop.rs:212:15
148+
--> $DIR/for_loop.rs:149:15
281149
|
282150
LL | for _v in vec.iter().next() {}
283151
| ^^^^^^^^^^^^^^^^^
284152
|
285153
= note: `-D clippy::iter-next-loop` implied by `-D warnings`
286154

287155
error: you are collect()ing an iterator and throwing away the result. Consider using an explicit for loop to exhaust the iterator
288-
--> $DIR/for_loop.rs:219:5
156+
--> $DIR/for_loop.rs:156:5
289157
|
290158
LL | vec.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>();
291159
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
292160
|
293161
= note: `-D clippy::unused-collect` implied by `-D warnings`
294162

295-
error: aborting due to 35 previous errors
163+
error: aborting due to 22 previous errors
296164

0 commit comments

Comments
 (0)