rust-lang / rust-lang/rust-clippy
Clippy suggests broken code in explicit_counter_loop lint
Open
Nobody has claimed this yet.
C-bug
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Running cargo clippy on this:
fn main() {
let mut arr = [0; 10];
let mut counter = 0;
for i in 0..arr.len() {
arr[i] = counter;
counter += 1;
}
}
Clippy suggests changing it to:
fn main() {
let mut arr = [0; 10];
let mut counter = 0;
for (counter, i) in (0..arr.len()).enumerate() {
arr[i] = counter;
counter += 1;
}
}
Which doesn't compile.
> cargo clippy --version
clippy 0.1.89 (2eef47813f 2025-05-22)
> cargo --version
cargo 1.89.0-nightly (47c911e9e 2025-05-14)
> rustc --version
rustc 1.89.0-nightly (2eef47813 2025-05-22)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with the supplied Rust example and cargo clippy, then locate the explicit_counter_loop lint implementation and its tests. Check the generated suggestion against the compiler; done means the suggested code compiles and preserves the loop's behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100