]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/clippy_lints/src/loops/empty_loop.rs
New upstream version 1.52.1+dfsg1
[rustc.git] / src / tools / clippy / clippy_lints / src / loops / empty_loop.rs
CommitLineData
f20569fa
XL
1use super::EMPTY_LOOP;
2use crate::utils::{is_in_panic_handler, is_no_std_crate, span_lint_and_help};
3
4use rustc_hir::{Block, Expr};
5use rustc_lint::LateContext;
6
7pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) {
8 if loop_block.stmts.is_empty() && loop_block.expr.is_none() && !is_in_panic_handler(cx, expr) {
9 let msg = "empty `loop {}` wastes CPU cycles";
10 let help = if is_no_std_crate(cx) {
11 "you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body"
12 } else {
13 "you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body"
14 };
15 span_lint_and_help(cx, EMPTY_LOOP, expr.span, msg, None, help);
16 }
17}