RS.CLIPPY.EMPTY_LOOP
Empty `loop {}`, which should block or sleep
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: empty_loop. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for empty loop expressions.
Why is this bad?
These busy loops burn CPU cycles without doing
anything. It is almost always a better idea to panic! than to have
a busy loop.
If panicking isn't possible, think of the environment and either:
- block on something
- sleep the thread for some microseconds
- yield or pause the thread
For std targets, this can be done with
std::thread::sleep
or std::thread::yield_now.
For no_std targets, doing this is more complicated, especially because
#[panic_handler]s can't panic. To stop/pause the thread, you will
probably need to invoke some target-specific intrinsic. Examples include:
Example
loop {}