Skip to content

Commit c48594c

Browse files
committed
Auto merge of #5085 - JohnTitor:split-up-test, r=phansch
Split up `needless_range_loop` ui test Part of #2038 changelog: none
2 parents 2c7cfa8 + 46b787d commit c48594c

File tree

4 files changed

+194
-189
lines changed

4 files changed

+194
-189
lines changed

tests/ui/needless_range_loop.rs

Lines changed: 2 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,10 @@
1-
#![allow(clippy::cognitive_complexity)]
1+
#![warn(clippy::needless_range_loop)]
22

33
static STATIC: [usize; 4] = [0, 1, 8, 16];
44
const CONST: [usize; 4] = [0, 1, 8, 16];
5-
6-
fn calc_idx(i: usize) -> usize {
7-
(i + i + 20) % 4
8-
}
5+
const MAX_LEN: usize = 42;
96

107
fn main() {
11-
const MAX_LEN: usize = 42;
12-
13-
let ns = vec![2, 3, 5, 7];
14-
15-
for i in 3..10 {
16-
println!("{}", ns[i]);
17-
}
18-
19-
for i in 3..10 {
20-
println!("{}", ns[i % 4]);
21-
}
22-
23-
for i in 3..10 {
24-
println!("{}", ns[i % ns.len()]);
25-
}
26-
27-
for i in 3..10 {
28-
println!("{}", ns[calc_idx(i)]);
29-
}
30-
31-
for i in 3..10 {
32-
println!("{}", ns[calc_idx(i) % 4]);
33-
}
34-
35-
let mut ms = vec![1, 2, 3, 4, 5, 6];
36-
for i in 0..ms.len() {
37-
ms[i] *= 2;
38-
}
39-
assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]);
40-
41-
let mut ms = vec![1, 2, 3, 4, 5, 6];
42-
for i in 0..ms.len() {
43-
let x = &mut ms[i];
44-
*x *= 2;
45-
}
46-
assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]);
47-
48-
let g = vec![1, 2, 3, 4, 5, 6];
49-
let glen = g.len();
50-
for i in 0..glen {
51-
let x: u32 = g[i + 1..].iter().sum();
52-
println!("{}", g[i] + x);
53-
}
54-
assert_eq!(g, vec![20, 18, 15, 11, 6, 0]);
55-
56-
let mut g = vec![1, 2, 3, 4, 5, 6];
57-
let glen = g.len();
58-
for i in 0..glen {
59-
g[i] = g[i + 1..].iter().sum();
60-
}
61-
assert_eq!(g, vec![20, 18, 15, 11, 6, 0]);
62-
63-
let x = 5;
64-
let mut vec = vec![0; 9];
65-
66-
for i in x..x + 4 {
67-
vec[i] += 1;
68-
}
69-
70-
let x = 5;
71-
let mut vec = vec![0; 10];
72-
73-
for i in x..=x + 4 {
74-
vec[i] += 1;
75-
}
76-
77-
let arr = [1, 2, 3];
78-
79-
for i in 0..3 {
80-
println!("{}", arr[i]);
81-
}
82-
83-
for i in 0..2 {
84-
println!("{}", arr[i]);
85-
}
86-
87-
for i in 1..3 {
88-
println!("{}", arr[i]);
89-
}
90-
918
let mut vec = vec![1, 2, 3, 4];
929
let vec2 = vec![1, 2, 3, 4];
9310
for i in 0..vec.len() {

tests/ui/needless_range_loop.stderr

Lines changed: 16 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,17 @@
1-
error: the loop variable `i` is only used to index `ns`.
2-
--> $DIR/needless_range_loop.rs:15:14
3-
|
4-
LL | for i in 3..10 {
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 ns.iter().take(10).skip(3) {
11-
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
13-
error: the loop variable `i` is only used to index `ms`.
14-
--> $DIR/needless_range_loop.rs:36:14
15-
|
16-
LL | for i in 0..ms.len() {
17-
| ^^^^^^^^^^^
18-
|
19-
help: consider using an iterator
20-
|
21-
LL | for <item> in &mut ms {
22-
| ^^^^^^ ^^^^^^^
23-
24-
error: the loop variable `i` is only used to index `ms`.
25-
--> $DIR/needless_range_loop.rs:42:14
26-
|
27-
LL | for i in 0..ms.len() {
28-
| ^^^^^^^^^^^
29-
|
30-
help: consider using an iterator
31-
|
32-
LL | for <item> in &mut ms {
33-
| ^^^^^^ ^^^^^^^
34-
35-
error: the loop variable `i` is only used to index `vec`.
36-
--> $DIR/needless_range_loop.rs:66:14
37-
|
38-
LL | for i in x..x + 4 {
39-
| ^^^^^^^^
40-
|
41-
help: consider using an iterator
42-
|
43-
LL | for <item> in vec.iter_mut().skip(x).take(4) {
44-
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
45-
461
error: the loop variable `i` is only used to index `vec`.
47-
--> $DIR/needless_range_loop.rs:73:14
48-
|
49-
LL | for i in x..=x + 4 {
50-
| ^^^^^^^^^
51-
|
52-
help: consider using an iterator
53-
|
54-
LL | for <item> in vec.iter_mut().skip(x).take(4 + 1) {
55-
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56-
57-
error: the loop variable `i` is only used to index `arr`.
58-
--> $DIR/needless_range_loop.rs:79:14
59-
|
60-
LL | for i in 0..3 {
61-
| ^^^^
62-
|
63-
help: consider using an iterator
64-
|
65-
LL | for <item> in &arr {
66-
| ^^^^^^ ^^^^
67-
68-
error: the loop variable `i` is only used to index `arr`.
69-
--> $DIR/needless_range_loop.rs:83:14
70-
|
71-
LL | for i in 0..2 {
72-
| ^^^^
73-
|
74-
help: consider using an iterator
75-
|
76-
LL | for <item> in arr.iter().take(2) {
77-
| ^^^^^^ ^^^^^^^^^^^^^^^^^^
78-
79-
error: the loop variable `i` is only used to index `arr`.
80-
--> $DIR/needless_range_loop.rs:87:14
81-
|
82-
LL | for i in 1..3 {
83-
| ^^^^
84-
|
85-
help: consider using an iterator
86-
|
87-
LL | for <item> in arr.iter().skip(1) {
88-
| ^^^^^^ ^^^^^^^^^^^^^^^^^^
89-
90-
error: the loop variable `i` is only used to index `vec`.
91-
--> $DIR/needless_range_loop.rs:93:14
2+
--> $DIR/needless_range_loop.rs:10:14
923
|
934
LL | for i in 0..vec.len() {
945
| ^^^^^^^^^^^^
956
|
7+
= note: `-D clippy::needless-range-loop` implied by `-D warnings`
968
help: consider using an iterator
979
|
9810
LL | for <item> in &vec {
9911
| ^^^^^^ ^^^^
10012

10113
error: the loop variable `i` is only used to index `vec`.
102-
--> $DIR/needless_range_loop.rs:102:14
14+
--> $DIR/needless_range_loop.rs:19:14
10315
|
10416
LL | for i in 0..vec.len() {
10517
| ^^^^^^^^^^^^
@@ -110,7 +22,7 @@ LL | for <item> in &vec {
11022
| ^^^^^^ ^^^^
11123

11224
error: the loop variable `j` is only used to index `STATIC`.
113-
--> $DIR/needless_range_loop.rs:107:14
25+
--> $DIR/needless_range_loop.rs:24:14
11426
|
11527
LL | for j in 0..4 {
11628
| ^^^^
@@ -121,7 +33,7 @@ LL | for <item> in &STATIC {
12133
| ^^^^^^ ^^^^^^^
12234

12335
error: the loop variable `j` is only used to index `CONST`.
124-
--> $DIR/needless_range_loop.rs:111:14
36+
--> $DIR/needless_range_loop.rs:28:14
12537
|
12638
LL | for j in 0..4 {
12739
| ^^^^
@@ -132,7 +44,7 @@ LL | for <item> in &CONST {
13244
| ^^^^^^ ^^^^^^
13345

13446
error: the loop variable `i` is used to index `vec`
135-
--> $DIR/needless_range_loop.rs:115:14
47+
--> $DIR/needless_range_loop.rs:32:14
13648
|
13749
LL | for i in 0..vec.len() {
13850
| ^^^^^^^^^^^^
@@ -143,7 +55,7 @@ LL | for (i, <item>) in vec.iter().enumerate() {
14355
| ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
14456

14557
error: the loop variable `i` is only used to index `vec2`.
146-
--> $DIR/needless_range_loop.rs:123:14
58+
--> $DIR/needless_range_loop.rs:40:14
14759
|
14860
LL | for i in 0..vec.len() {
14961
| ^^^^^^^^^^^^
@@ -154,7 +66,7 @@ LL | for <item> in vec2.iter().take(vec.len()) {
15466
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15567

15668
error: the loop variable `i` is only used to index `vec`.
157-
--> $DIR/needless_range_loop.rs:127:14
69+
--> $DIR/needless_range_loop.rs:44:14
15870
|
15971
LL | for i in 5..vec.len() {
16072
| ^^^^^^^^^^^^
@@ -165,7 +77,7 @@ LL | for <item> in vec.iter().skip(5) {
16577
| ^^^^^^ ^^^^^^^^^^^^^^^^^^
16678

16779
error: the loop variable `i` is only used to index `vec`.
168-
--> $DIR/needless_range_loop.rs:131:14
80+
--> $DIR/needless_range_loop.rs:48:14
16981
|
17082
LL | for i in 0..MAX_LEN {
17183
| ^^^^^^^^^^
@@ -176,7 +88,7 @@ LL | for <item> in vec.iter().take(MAX_LEN) {
17688
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^
17789

17890
error: the loop variable `i` is only used to index `vec`.
179-
--> $DIR/needless_range_loop.rs:135:14
91+
--> $DIR/needless_range_loop.rs:52:14
18092
|
18193
LL | for i in 0..=MAX_LEN {
18294
| ^^^^^^^^^^^
@@ -187,7 +99,7 @@ LL | for <item> in vec.iter().take(MAX_LEN + 1) {
18799
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
188100

189101
error: the loop variable `i` is only used to index `vec`.
190-
--> $DIR/needless_range_loop.rs:139:14
102+
--> $DIR/needless_range_loop.rs:56:14
191103
|
192104
LL | for i in 5..10 {
193105
| ^^^^^
@@ -198,7 +110,7 @@ LL | for <item> in vec.iter().take(10).skip(5) {
198110
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
199111

200112
error: the loop variable `i` is only used to index `vec`.
201-
--> $DIR/needless_range_loop.rs:143:14
113+
--> $DIR/needless_range_loop.rs:60:14
202114
|
203115
LL | for i in 5..=10 {
204116
| ^^^^^^
@@ -209,7 +121,7 @@ LL | for <item> in vec.iter().take(10 + 1).skip(5) {
209121
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
210122

211123
error: the loop variable `i` is used to index `vec`
212-
--> $DIR/needless_range_loop.rs:147:14
124+
--> $DIR/needless_range_loop.rs:64:14
213125
|
214126
LL | for i in 5..vec.len() {
215127
| ^^^^^^^^^^^^
@@ -220,7 +132,7 @@ LL | for (i, <item>) in vec.iter().enumerate().skip(5) {
220132
| ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
221133

222134
error: the loop variable `i` is used to index `vec`
223-
--> $DIR/needless_range_loop.rs:151:14
135+
--> $DIR/needless_range_loop.rs:68:14
224136
|
225137
LL | for i in 5..10 {
226138
| ^^^^^
@@ -231,7 +143,7 @@ LL | for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
231143
| ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
232144

233145
error: the loop variable `i` is used to index `vec`
234-
--> $DIR/needless_range_loop.rs:156:14
146+
--> $DIR/needless_range_loop.rs:73:14
235147
|
236148
LL | for i in 0..vec.len() {
237149
| ^^^^^^^^^^^^
@@ -241,5 +153,5 @@ help: consider using an iterator
241153
LL | for (i, <item>) in vec.iter_mut().enumerate() {
242154
| ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
243155

244-
error: aborting due to 22 previous errors
156+
error: aborting due to 14 previous errors
245157

0 commit comments

Comments
 (0)