RS.CLIPPY.MUT_RANGE_BOUND
For loop over a range where one of the bounds is a mutable variable
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: mut_range_bound. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for loops with a range bound that is a mutable variable.
Why is this bad?
One might think that modifying the mutable variable changes the loop bounds. It doesn't.
Known problems
False positive when mutation is followed by a break, but the break is not immediately
after the mutation:
let mut x = 5;
for _ in 0..x {
x += 1; // x is a range bound that is mutated
..; // some other expression
break; // leaves the loop, so mutation is not an issue
}
False positive on nested loops (#6072)
Example
let mut foo = 42;
for i in 0..foo {
foo -= 1;
println!("{i}"); // prints numbers from 0 to 41, not 0 to 21
}