]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/loops/empty_loop.rs
Rollup merge of #105128 - Sp00ph:vec_vec_deque_conversion, r=dtolnay
[rust.git] / src / tools / clippy / clippy_lints / src / loops / empty_loop.rs
1 use super::EMPTY_LOOP;
2 use clippy_utils::diagnostics::span_lint_and_help;
3 use clippy_utils::{is_in_panic_handler, is_no_std_crate};
4
5 use rustc_hir::{Block, Expr};
6 use rustc_lint::LateContext;
7
8 pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, loop_block: &Block<'_>) {
9     if loop_block.stmts.is_empty() && loop_block.expr.is_none() && !is_in_panic_handler(cx, expr) {
10         let msg = "empty `loop {}` wastes CPU cycles";
11         let help = if is_no_std_crate(cx) {
12             "you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body"
13         } else {
14             "you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body"
15         };
16         span_lint_and_help(cx, EMPTY_LOOP, expr.span, msg, None, help);
17     }
18 }