rust-lang / rust-lang/rust-clippy
`std::thread::park` is a better suggestion for fixing `clippy::empty_loop`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Description
I got the following warning:
warning: empty `loop {}` wastes CPU cycles
--> src/sequences/fibonacci.rs:717:18
|
717 | _ => loop {},
| ^^^^^^^
|
= help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_loop
= note: `#[warn(clippy::empty_loop)]` on by default
It would be better to instead suggest or to also suggest std::thread::park() when the loop is supposed to truly do nothing, which uses even less CPU cycles than sleeping or yielding does. If this suggestion is accepted, changing the suggestions at https://rust-lang.github.io/rust-clippy/master/index.html#empty_loop would be needed as well.
Version
rustc 1.71.1 (eb26296b5 2023-08-03)
binary: rustc
commit-hash: eb26296b556cef10fb713a38f3d16b9886080f26
commit-date: 2023-08-03
host: x86_64-unknown-linux-gnu
release: 1.71.1
LLVM version: 16.0.5
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the clippy::empty_loop lint entry point and compare its current help text with the requested std:🧵:park alternative. Check the linked empty_loop documentation as well; done means the diagnostic and documented suggestions consistently explain the accepted alternative without wasting CPU cycles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100