summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/empty_loop.txt
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:03:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:03:36 +0000
commit17d40c6057c88f4c432b0d7bac88e1b84cb7e67f (patch)
tree3f66c4a5918660bb8a758ab6cda5ff8ee4f6cdcd /src/tools/clippy/src/docs/empty_loop.txt
parentAdding upstream version 1.64.0+dfsg1. (diff)
downloadrustc-17d40c6057c88f4c432b0d7bac88e1b84cb7e67f.tar.xz
rustc-17d40c6057c88f4c432b0d7bac88e1b84cb7e67f.zip
Adding upstream version 1.65.0+dfsg1.upstream/1.65.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/src/docs/empty_loop.txt')
-rw-r--r--src/tools/clippy/src/docs/empty_loop.txt27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/empty_loop.txt b/src/tools/clippy/src/docs/empty_loop.txt
new file mode 100644
index 000000000..fea49a74d
--- /dev/null
+++ b/src/tools/clippy/src/docs/empty_loop.txt
@@ -0,0 +1,27 @@
+### 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`](https://doc.rust-lang.org/std/thread/fn.sleep.html)
+or [`std::thread::yield_now`](https://doc.rust-lang.org/std/thread/fn.yield_now.html).
+
+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:
+ - [`x86_64::instructions::hlt`](https://docs.rs/x86_64/0.12.2/x86_64/instructions/fn.hlt.html)
+ - [`cortex_m::asm::wfi`](https://docs.rs/cortex-m/0.6.3/cortex_m/asm/fn.wfi.html)
+
+### Example
+```
+loop {}
+``` \ No newline at end of file