]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | use super::EMPTY_LOOP; |
2 | use crate::utils::{is_in_panic_handler, is_no_std_crate, span_lint_and_help}; | |
3 | ||
4 | use rustc_hir::{Block, Expr}; | |
5 | use rustc_lint::LateContext; | |
6 | ||
7 | pub(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 | } |