about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Wright <mikerite@lavabit.com>2019-07-06 19:35:08 +0200
committerMichael Wright <mikerite@lavabit.com>2019-07-06 19:35:08 +0200
commitadcc02ed8ac1cdf040719d5b32574fb6fccb674a (patch)
treecd46c2ee2fdbee38ca24a0ac37bf7c79674a0e01
parent0579c3e0aa21df8c63cc10036107027aee723fd8 (diff)
downloadrust-adcc02ed8ac1cdf040719d5b32574fb6fccb674a.tar.gz
rust-adcc02ed8ac1cdf040719d5b32574fb6fccb674a.zip
Address reviews
-rw-r--r--clippy_lints/src/loops.rs14
-rw-r--r--clippy_lints/src/utils/author.rs2
-rw-r--r--clippy_lints/src/utils/higher.rs17
3 files changed, 21 insertions, 12 deletions
diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs
index cd36afba6af..c3ca1de3a23 100644
--- a/clippy_lints/src/loops.rs
+++ b/clippy_lints/src/loops.rs
@@ -488,7 +488,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
                 },
                 NeverLoopResult::MayContinueMainLoop | NeverLoopResult::Otherwise => (),
             }
-        };
+        }
 
         // check for `loop { if let {} else break }` that could be `while let`
         // (also matches an explicit "match" instead of "if let")
@@ -587,16 +587,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
             }
         }
 
-        if_chain! {
-            if let ExprKind::Loop(block, _, LoopSource::While) = &expr.node;
-            if let Block { expr: Some(expr), .. } = &**block;
-            if let ExprKind::Match(cond, arms, MatchSource::WhileDesugar) = &expr.node;
-            if let ExprKind::DropTemps(cond) = &cond.node;
-            if let [arm, ..] = &arms[..];
-            if let Arm { body, .. } = arm;
-            then {
-                check_infinite_loop(cx, cond, body);
-            }
+        if let Some((cond, body)) = higher::while_loop(&expr) {
+            check_infinite_loop(cx, cond, body);
         }
 
         check_needless_collect(expr, cx);
diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs
index a00eee67166..f419338097d 100644
--- a/clippy_lints/src/utils/author.rs
+++ b/clippy_lints/src/utils/author.rs
@@ -702,7 +702,7 @@ fn loop_desugaring_name(des: hir::LoopSource) -> &'static str {
     match des {
         hir::LoopSource::ForLoop => "LoopSource::ForLoop",
         hir::LoopSource::Loop => "LoopSource::Loop",
-        hir::LoopSource::While => "LoopSource::WhileDesugar",
+        hir::LoopSource::While => "LoopSource::While",
         hir::LoopSource::WhileLet => "LoopSource::WhileLet",
     }
 }
diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs
index dda05d3fbc5..6fb2a3622c6 100644
--- a/clippy_lints/src/utils/higher.rs
+++ b/clippy_lints/src/utils/higher.rs
@@ -199,6 +199,23 @@ pub fn for_loop(expr: &hir::Expr) -> Option<(&hir::Pat, &hir::Expr, &hir::Expr)>
     None
 }
 
+/// Recover the essential nodes of a desugared while loop:
+/// `while cond { body }` becomes `(cond, body)`.
+pub fn while_loop(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr)> {
+    if_chain! {
+        if let hir::ExprKind::Loop(block, _, hir::LoopSource::While) = &expr.node;
+        if let hir::Block { expr: Some(expr), .. } = &**block;
+        if let hir::ExprKind::Match(cond, arms, hir::MatchSource::WhileDesugar) = &expr.node;
+        if let hir::ExprKind::DropTemps(cond) = &cond.node;
+        if let [arm, ..] = &arms[..];
+        if let hir::Arm { body, .. } = arm;
+        then {
+            return Some((cond, body));
+        }
+    }
+    None
+}
+
 /// Recover the essential nodes of a desugared if block
 /// `if cond { then } else { els }` becomes `(cond, then, Some(els))`
 pub fn if_block(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr, Option<&hir::Expr>)> {