rust-lang / rust-lang/rust-clippy
FP mut_range_bound: range bound modified inside enclosing loop
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
In this code we first create the mut range bound, and mutate it in another loop which means the loop that actually uses the range is executed several times with different bounds (even if it is true that inside the usage of the range, changing the index has no effect on the inner loop.
fn main() {
let mut i = 3;
while i < 1000 { // this invalidates the lint warning
for x in i..9 { // this will be unaffected by the i+=4 but we modify i AND LOOP AGAIN!
i += 4; // lint warns about this
}
if i > 12 {
return;
}
}
}
The lint should probably only fire if range bound variable and the range bounds usage are in the same scope?
Meta
clippy 0.0.212 (1fd5b9d 2020-09-20)
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 reproducing the example and tracing the mut_range_bound lint implementation. Compare the lint’s behavior when the range is reused by an enclosing loop, and verify that the completed change no longer warns for this case while preserving the warning for the intended same-scope mutation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100