Right now, we have a style lint against the following code:
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
halt or pause intrinsic.
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_loop lint for no_std crates.
- Have a
no_std specific help message.
- Disable this lint automatically in
#[panic_handler]s
- As an alternative, we could just disable this lint for
no_std binaries (while keeping it on for no_std libraries).
- The only uses of deadloops in the Rustonomicon are inside of
#[panic_handler].
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
Right now, we have a style lint against the following code:
Note that this is no longer undefined behavior (since rust-lang/rust#77972).
Currently, there is no way to have a
no_stdbinary or library use theempty_looplint.Even adding
#![deny(clippy::empty_loop)]to a crate does nothing. This is because #5086 (fixing #3746), made the lint essentially not exist forno_stdcrates.Furthermore, even in
no_stdcrates, using a "hot" deadloop is almost always not what you want (as it burns a bunch of CPU, and can cause crashes). Even on ano_stdtarget, a user should either:haltorpauseintrinsic.Note,
core::sync::atomic::spin_loop_hintis not a good recommendation here, aspauseisn't meant for dead-loops (it's designed for spin-locks). See rust-lang/rust#77924In my opinion, we should:
empty_looplint forno_stdcrates.no_stdspecific help message.#[panic_handler]sno_stdbinaries (while keeping it on forno_stdlibraries).#[panic_handler].Our documentation for fixing this (on
stdandno_std) is part of #6162CC (people involved with this change last time): @therealprof, @oli-obk, @eddyp, @Areredify, @phansch