@@ -481,17 +481,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
481481 }
482482
483483 // check for never_loop
484- match expr. node {
485- ExprKind :: While ( _, ref block, _) | ExprKind :: Loop ( ref block, _, _) => {
486- match never_loop_block ( block, expr. hir_id ) {
487- NeverLoopResult :: AlwaysBreak => {
488- span_lint ( cx, NEVER_LOOP , expr. span , "this loop never actually loops" )
489- } ,
490- NeverLoopResult :: MayContinueMainLoop | NeverLoopResult :: Otherwise => ( ) ,
491- }
492- } ,
493- _ => ( ) ,
494- }
484+ if let ExprKind :: Loop ( ref block, _, _) = expr. node {
485+ match never_loop_block ( block, expr. hir_id ) {
486+ NeverLoopResult :: AlwaysBreak => {
487+ span_lint ( cx, NEVER_LOOP , expr. span , "this loop never actually loops" )
488+ } ,
489+ NeverLoopResult :: MayContinueMainLoop | NeverLoopResult :: Otherwise => ( ) ,
490+ }
491+ } ;
495492
496493 // check for `loop { if let {} else break }` that could be `while let`
497494 // (also matches an explicit "match" instead of "if let")
@@ -590,9 +587,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
590587 }
591588 }
592589
593- // check for while loops which conditions never change
594- if let ExprKind :: While ( ref cond, _, _) = expr. node {
595- check_infinite_loop ( cx, cond, expr) ;
590+ if_chain ! {
591+ if let ExprKind :: Loop ( block, _, LoopSource :: While ) = & expr. node;
592+ if let Block { expr: Some ( expr) , .. } = & * * block;
593+ if let ExprKind :: Match ( cond, arms, MatchSource :: WhileDesugar ) = & expr. node;
594+ if let ExprKind :: DropTemps ( cond) = & cond. node;
595+ if let [ arm, ..] = & arms[ ..] ;
596+ if let Arm { body, .. } = arm;
597+ then {
598+ check_infinite_loop( cx, cond, body) ;
599+ }
596600 }
597601
598602 check_needless_collect ( expr, cx) ;
@@ -701,12 +705,6 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
701705 // Break can come from the inner loop so remove them.
702706 absorb_break ( & never_loop_block ( b, main_loop_id) )
703707 } ,
704- ExprKind :: While ( ref e, ref b, _) => {
705- let e = never_loop_expr ( e, main_loop_id) ;
706- let result = never_loop_block ( b, main_loop_id) ;
707- // Break can come from the inner loop so remove them.
708- combine_seq ( e, absorb_break ( & result) )
709- } ,
710708 ExprKind :: Match ( ref e, ref arms, _) => {
711709 let e = never_loop_expr ( e, main_loop_id) ;
712710 if arms. is_empty ( ) {
@@ -2202,7 +2200,7 @@ fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
22022200
22032201fn is_loop ( expr : & Expr ) -> bool {
22042202 match expr. node {
2205- ExprKind :: Loop ( ..) | ExprKind :: While ( .. ) => true ,
2203+ ExprKind :: Loop ( ..) => true ,
22062204 _ => false ,
22072205 }
22082206}
@@ -2239,11 +2237,10 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr)
22392237 return false ;
22402238 }
22412239 match cx. tcx . hir ( ) . find ( parent) {
2242- Some ( Node :: Expr ( expr) ) => match expr . node {
2243- ExprKind :: Loop ( .. ) | ExprKind :: While ( ..) => {
2240+ Some ( Node :: Expr ( expr) ) => {
2241+ if let ExprKind :: Loop ( ..) = expr . node {
22442242 return true ;
2245- } ,
2246- _ => ( ) ,
2243+ } ;
22472244 } ,
22482245 Some ( Node :: Block ( block) ) => {
22492246 let mut block_visitor = LoopNestVisitor {
0 commit comments