rust-lang / rust-lang/rust-clippy

`std::thread::park` is a better suggestion for fixing `clippy::empty_loop`

Open
#11,388 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.