Open
Description
Summary
When mutating a variable, that serves as a range bound for an outer loop, but then immediately continuing a loop even further up, a warning of type mutate_range_bound
is still emitted, even though the affected loop will be exited, similar to using a break.
This behavior is similar to that described in the issue #7532
Lint Name
mutate_range_bound
Reproducer
I tried this code:
let mut collection = [4, 3, 2, 1];
let mut i = 0;
'outer: while i < collection.len() {
for j in 0..i {
if collection[j] > collection[i] {
collection.swap(j, i);
i -= 1;
continue 'outer;
}
}
i += 1;
}
I saw this happen:
warning: attempt to mutate range bound within loop
--> src/main.rs:133:17
|
133 | i -= 1;
| ^
|
= note: the range of the loop is unchanged
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mut_range_bound
I expected to see this happen:
No warning should be emitted, as the affected loop is immediately exited by continuing the outer loop.
Version
rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1
Additional Labels
No response