-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Right now, we have a style lint against the following code:
loop {}Note that this is no longer undefined behavior (since rust-lang/rust#77972).
Currently, there is no way to have a no_std binary or library use the empty_loop lint.
Even adding #![deny(clippy::empty_loop)] to a crate does nothing. This is because #5086 (fixing #3746), made the lint essentially not exist for no_std crates.
Furthermore, even in no_std crates, using a "hot" deadloop is almost always not what you want (as it burns a bunch of CPU, and can cause crashes). Even on a no_std target, a user should either:
- Panic
- Call a platform-specific
haltorpauseintrinsic.
Note, core::sync::atomic::spin_loop_hint is not a good recommendation here, as pause isn't meant for dead-loops (it's designed for spin-locks). See rust-lang/rust#77924
In my opinion, we should:
- Reenable the
empty_looplint forno_stdcrates. - Have a
no_stdspecific help message. - Disable this lint automatically in
#[panic_handler]s- As an alternative, we could just disable this lint for
no_stdbinaries (while keeping it on forno_stdlibraries). - The only uses of deadloops in the Rustonomicon are inside of
#[panic_handler].
- As an alternative, we could just disable this lint for
Our documentation for fixing this (on std and no_std) is part of #6162
CC (people involved with this change last time): @therealprof, @oli-obk, @eddyp, @Areredify, @phansch