RS.CLIPPY.EXPLICIT_COUNTER_LOOP
For-looping with an explicit counter when `_.enumerate()` would do
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: explicit_counter_loop. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for loops over slices with an explicit counter
and suggests the use of .enumerate().
Why is this bad?
Using .enumerate() makes the intent more clear,
declutters the code and may be faster in some instances.
Example
let mut i = 0;
for item in &v {
bar(i, *item);
i += 1;
}
Use instead:
for (i, item) in v.iter().enumerate() { bar(i, *item); }