Why is this an issue?

Having an immutable condition in a while loop can result in an infinite loop as the condition will never change, causing the loop to run indefinitely.

Code examples

Noncompliant code example

let i = 0;
while i > 10 {
    println!("let me loop forever!"); // Noncompliant: 'i' does not change within the loop body
}

Compliant solution

let mut i = 0;
while i <= 10 {
    println!("looping: {}", i); // Compliant: 'i' gets incremented within the loop body
    i += 1;
}

Resources

Documentation