RS.CLIPPY.WHILE_IMMUTABLE_CONDITION

Variables used within while expression are not mutated in the body

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: while_immutable_condition. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks whether variables used within while loop condition can be (and are) mutated in the body.

Why is this bad?

If the condition is unchanged, entering the body of the loop will lead to an infinite loop.

Known problems

If the while-loop is in a closure, the check for mutation of the condition variables in the body can cause false negatives. For example when only Upvara is in the condition and only Upvarb gets mutated in the body, the lint will not trigger.

Example

let i = 0;
while i > 10 {
    println!("let me loop forever!");
}