2 use clippy_utils::diagnostics::span_lint_and_help;
3 use clippy_utils::{is_in_panic_handler, is_no_std_crate};
5 use rustc_hir::{Block, Expr};
6 use rustc_lint::LateContext;
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"
14 "you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body"
16 span_lint_and_help(cx, EMPTY_LOOP, expr.span, msg, None, help);