rust-lang / rust-lang/rust-clippy
for loop with mutable binding
Open
Nobody has claimed this yet.
A-lint
S-needs-discussion
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Suggest replacing
for i in 0..11 {
let mut i = i;
i += 1;
println!("i: {}", i);
}
with
for mut i in 0..11 {
i += 1;
println!("i: {}", i);
}
(I did not even know that this was possible, until I saw this post on reddit)
Categories (optional)
- Kind:
clippy::style
What is the advantage of the recommended code over the original code
less code -> easier to read
Drawbacks
None.
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
Start by reviewing the issue's two Rust examples and the existing clippy::style lint implementations and tests. Determine how a lint can recognize the mutable binding form and suggest the direct for-loop binding; done means the simpler form is suggested without changing behavior, with coverage for the shown example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100