RS.CLIPPY.INFINITE_LOOP
Possibly unintended infinite loop
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: infinite_loop. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for infinite loops in a function where the return type is not !
and lint accordingly.
Why restrict this?
Making the return type ! serves as documentation that the function does not return.
If the function is not intended to loop infinitely, then this lint may detect a bug.
Example
fn run_forever() {
loop {
// do something
}
}
If infinite loops are as intended:
fn run_forever() -> ! {
loop {
// do something
}
}
Otherwise add a break or return condition:
fn run_forever() {
loop {
// do something
if condition {
break;
}
}
}