1
+ mod empty_loop;
1
2
mod explicit_counter_loop;
2
3
mod for_loop_arg;
3
4
mod for_loop_over_map_kv;
@@ -14,10 +15,7 @@ mod utils;
14
15
mod while_let_on_iterator;
15
16
16
17
use crate :: utils:: sugg:: Sugg ;
17
- use crate :: utils:: {
18
- higher, is_in_panic_handler, is_no_std_crate, snippet_with_applicability, span_lint_and_help, span_lint_and_sugg,
19
- sugg,
20
- } ;
18
+ use crate :: utils:: { higher, snippet_with_applicability, span_lint_and_sugg, sugg} ;
21
19
use rustc_errors:: Applicability ;
22
20
use rustc_hir:: { Block , Expr , ExprKind , LoopSource , MatchSource , Pat , StmtKind } ;
23
21
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
@@ -565,15 +563,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
565
563
// (even if the "match" or "if let" is used for declaration)
566
564
if let ExprKind :: Loop ( ref block, _, LoopSource :: Loop , _) = expr. kind {
567
565
// also check for empty `loop {}` statements, skipping those in #[panic_handler]
568
- if block. stmts . is_empty ( ) && block. expr . is_none ( ) && !is_in_panic_handler ( cx, expr) {
569
- let msg = "empty `loop {}` wastes CPU cycles" ;
570
- let help = if is_no_std_crate ( cx. tcx . hir ( ) . krate ( ) ) {
571
- "you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body"
572
- } else {
573
- "you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body"
574
- } ;
575
- span_lint_and_help ( cx, EMPTY_LOOP , expr. span , msg, None , help) ;
576
- }
566
+ empty_loop:: check_empty_loop ( cx, expr, block) ;
577
567
578
568
// extract the expression from the first statement (if any) in a block
579
569
let inner_stmt_expr = extract_expr_from_first_stmt ( block) ;
0 commit comments