@@ -481,16 +481,13 @@ 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- _ => ( ) ,
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+ }
494491 }
495492
496493 // check for `loop { if let {} else break }` that could be `while let`
@@ -590,9 +587,8 @@ 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 let Some ( ( cond, body) ) = higher:: while_loop ( & expr) {
591+ check_infinite_loop ( cx, cond, body) ;
596592 }
597593
598594 check_needless_collect ( expr, cx) ;
@@ -701,12 +697,6 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
701697 // Break can come from the inner loop so remove them.
702698 absorb_break ( & never_loop_block ( b, main_loop_id) )
703699 } ,
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- } ,
710700 ExprKind :: Match ( ref e, ref arms, _) => {
711701 let e = never_loop_expr ( e, main_loop_id) ;
712702 if arms. is_empty ( ) {
@@ -2202,7 +2192,7 @@ fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
22022192
22032193fn is_loop ( expr : & Expr ) -> bool {
22042194 match expr. node {
2205- ExprKind :: Loop ( ..) | ExprKind :: While ( .. ) => true ,
2195+ ExprKind :: Loop ( ..) => true ,
22062196 _ => false ,
22072197 }
22082198}
@@ -2239,11 +2229,10 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr)
22392229 return false ;
22402230 }
22412231 match cx. tcx . hir ( ) . find ( parent) {
2242- Some ( Node :: Expr ( expr) ) => match expr . node {
2243- ExprKind :: Loop ( .. ) | ExprKind :: While ( ..) => {
2232+ Some ( Node :: Expr ( expr) ) => {
2233+ if let ExprKind :: Loop ( ..) = expr . node {
22442234 return true ;
2245- } ,
2246- _ => ( ) ,
2235+ } ;
22472236 } ,
22482237 Some ( Node :: Block ( block) ) => {
22492238 let mut block_visitor = LoopNestVisitor {
0 commit comments