Skip to content

Commit b8178c1

Browse files
committed
Add Path and PathBuf tests
1 parent efb9587 commit b8178c1

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/tools/clippy/tests/ui/explicit_counter_loop.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![warn(clippy::explicit_counter_loop)]
22

3+
use std::path::{Path, PathBuf};
4+
35
fn main() {
46
let mut vec = vec![1, 2, 3, 4];
57
let mut _index = 0;
@@ -22,6 +24,18 @@ fn main() {
2224
for _v in vec {
2325
_index += 1;
2426
}
27+
28+
let path = Path::new("");
29+
let mut _index = 0;
30+
for _v in path.iter() {
31+
_index += 1
32+
}
33+
34+
let pathbuf = PathBuf::new();
35+
let mut _index = 0;
36+
for _v in pathbuf.iter() {
37+
_index += 1;
38+
}
2539
}
2640

2741
mod issue_1219 {
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,58 @@
11
error: the variable `_index` is used as a loop counter.
2-
--> $DIR/explicit_counter_loop.rs:6:5
2+
--> $DIR/explicit_counter_loop.rs:8:5
33
|
44
LL | for _v in &vec {
55
| ^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter().enumerate()`
66
|
77
= note: `-D clippy::explicit-counter-loop` implied by `-D warnings`
88

99
error: the variable `_index` is used as a loop counter.
10-
--> $DIR/explicit_counter_loop.rs:12:5
10+
--> $DIR/explicit_counter_loop.rs:14:5
1111
|
1212
LL | for _v in &vec {
1313
| ^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter().enumerate()`
1414

1515
error: the variable `_index` is used as a loop counter.
16-
--> $DIR/explicit_counter_loop.rs:17:5
16+
--> $DIR/explicit_counter_loop.rs:19:5
1717
|
1818
LL | for _v in &mut vec {
1919
| ^^^^^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter_mut().enumerate()`
2020

2121
error: the variable `_index` is used as a loop counter.
22-
--> $DIR/explicit_counter_loop.rs:22:5
22+
--> $DIR/explicit_counter_loop.rs:24:5
2323
|
2424
LL | for _v in vec {
2525
| ^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.into_iter().enumerate()`
2626

27+
error: the variable `_index` is used as a loop counter.
28+
--> $DIR/explicit_counter_loop.rs:30:5
29+
|
30+
LL | for _v in path.iter() {
31+
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in path.iter().enumerate()`
32+
33+
error: the variable `_index` is used as a loop counter.
34+
--> $DIR/explicit_counter_loop.rs:36:5
35+
|
36+
LL | for _v in pathbuf.iter() {
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in pathbuf.iter().enumerate()`
38+
2739
error: the variable `count` is used as a loop counter.
28-
--> $DIR/explicit_counter_loop.rs:61:9
40+
--> $DIR/explicit_counter_loop.rs:75:9
2941
|
3042
LL | for ch in text.chars() {
3143
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()`
3244

3345
error: the variable `count` is used as a loop counter.
34-
--> $DIR/explicit_counter_loop.rs:72:9
46+
--> $DIR/explicit_counter_loop.rs:86:9
3547
|
3648
LL | for ch in text.chars() {
3749
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()`
3850

3951
error: the variable `count` is used as a loop counter.
40-
--> $DIR/explicit_counter_loop.rs:130:9
52+
--> $DIR/explicit_counter_loop.rs:144:9
4153
|
4254
LL | for _i in 3..10 {
4355
| ^^^^^^^^^^^^^^^ help: consider using: `for (count, _i) in (3..10).enumerate()`
4456

45-
error: aborting due to 7 previous errors
57+
error: aborting due to 9 previous errors
4658

0 commit comments

Comments
 (0)