Open
Description
Summary
Hello, While coding on my Rust project i encountered something that would definitely make sense to have as a clippy lint.
Problematic code
let array = [1, 2, 3];
for (i, _) in array.iter().enumerate() {
// the array data is not used we only need the len
}
Better alternative
let array = [1, 2, 3];
for i in 0..array.len() {
// we only use the len
}
This is cleaner and also may faster since we don't have to iterate over the array anymore
Lint Name
uneeded_iter_loop
Reproducer
I tried this code:
let array = [1, 2, 3];
for (i, _) in array.iter().enumerate() {
// the array data is not used we only need the len
}
I expected to see this happen:
A clippy warn
Instead, this happened:
No clippy warn
Version
rustc: 1.85-stable