Summary
The lint currently fails to trigger when a manually maintained loop counter does not start at 0.
Lint Name
explicit_counter_loop
Reproducer
I tried this code:
pub fn m1(v: Vec<u8>) {
let mut i = 1;
for item in &v {
black_box((i, *item));
i += 1;
}
}
https://rust.godbolt.org/z/oG1h3f1nY
I expected to see this happen:
warning: the variable `i` is used as a loop counter
--> <source>:5:5
|
5 | for item in &v {
| ^^^^^^^^^^^^^^ help: consider using: `for (i, item) in (1..).zip(v.iter())`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_counter_loop
= note: `#[warn(clippy::explicit_counter_loop)]` on by default
warning: 1 warning emitted
Instead, this happened:
Lint was not triggered.
Version
Summary
The lint currently fails to trigger when a manually maintained loop counter does not start at 0.
Lint Name
explicit_counter_loopReproducer
I tried this code:
https://rust.godbolt.org/z/oG1h3f1nY
I expected to see this happen:
Instead, this happened:
Lint was not triggered.
Version