]> git.lizzy.rs Git - rust.git/commitdiff
Fix breakage due to rust-lang/rust#61988
authorMichael Wright <mikerite@lavabit.com>
Sat, 6 Jul 2019 17:06:49 +0000 (19:06 +0200)
committerMichael Wright <mikerite@lavabit.com>
Sat, 6 Jul 2019 17:06:49 +0000 (19:06 +0200)
clippy_lints/src/loops.rs
clippy_lints/src/shadow.rs
clippy_lints/src/unused_label.rs
clippy_lints/src/utils/author.rs
clippy_lints/src/utils/hir_utils.rs
clippy_lints/src/utils/inspector.rs
clippy_lints/src/utils/sugg.rs

index fccf8694ec514995b30c3b84deabfc0366240237..cd36afba6af435ffa7babacd9fba612b22d55f38 100644 (file)
@@ -481,17 +481,14 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
         }
 
         // check for never_loop
-        match expr.node {
-            ExprKind::While(_, ref block, _) | ExprKind::Loop(ref block, _, _) => {
-                match never_loop_block(block, expr.hir_id) {
-                    NeverLoopResult::AlwaysBreak => {
-                        span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops")
-                    },
-                    NeverLoopResult::MayContinueMainLoop | NeverLoopResult::Otherwise => (),
-                }
-            },
-            _ => (),
-        }
+        if let ExprKind::Loop(ref block, _, _) = expr.node {
+            match never_loop_block(block, expr.hir_id) {
+                NeverLoopResult::AlwaysBreak => {
+                    span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually 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")
@@ -590,9 +587,16 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
             }
         }
 
-        // check for while loops which conditions never change
-        if let ExprKind::While(ref cond, _, _) = expr.node {
-            check_infinite_loop(cx, cond, expr);
+        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);
+            }
         }
 
         check_needless_collect(expr, cx);
@@ -701,12 +705,6 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
             // Break can come from the inner loop so remove them.
             absorb_break(&never_loop_block(b, main_loop_id))
         },
-        ExprKind::While(ref e, ref b, _) => {
-            let e = never_loop_expr(e, main_loop_id);
-            let result = never_loop_block(b, main_loop_id);
-            // Break can come from the inner loop so remove them.
-            combine_seq(e, absorb_break(&result))
-        },
         ExprKind::Match(ref e, ref arms, _) => {
             let e = never_loop_expr(e, main_loop_id);
             if arms.is_empty() {
@@ -2202,7 +2200,7 @@ fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
 
 fn is_loop(expr: &Expr) -> bool {
     match expr.node {
-        ExprKind::Loop(..) | ExprKind::While(..) => true,
+        ExprKind::Loop(..) => true,
         _ => false,
     }
 }
@@ -2239,11 +2237,10 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr)
             return false;
         }
         match cx.tcx.hir().find(parent) {
-            Some(Node::Expr(expr)) => match expr.node {
-                ExprKind::Loop(..) | ExprKind::While(..) => {
+            Some(Node::Expr(expr)) => {
+                if let ExprKind::Loop(..) = expr.node {
                     return true;
-                },
-                _ => (),
+                };
             },
             Some(Node::Block(block)) => {
                 let mut block_visitor = LoopNestVisitor {
index 95cd118c98ebaaba0b72d1fc4c71cc9b52d2b917..c75e33e8406ca0bf725d05acd506f9aa3a533046 100644 (file)
@@ -319,10 +319,6 @@ fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, bindings:
                 check_expr(cx, e, bindings)
             }
         },
-        ExprKind::While(ref cond, ref block, _) => {
-            check_expr(cx, cond, bindings);
-            check_block(cx, block, bindings);
-        },
         ExprKind::Match(ref init, ref arms, _) => {
             check_expr(cx, init, bindings);
             let len = bindings.len();
index a9d78d30f2bf48d748a605f6ac0518bb90ef471a..9c02c1c31042abf6f5ffad5293d6ee29fe5877d6 100644 (file)
@@ -68,7 +68,7 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
                     self.labels.remove(&label.ident.as_str());
                 }
             },
-            hir::ExprKind::Loop(_, Some(label), _) | hir::ExprKind::While(_, _, Some(label)) => {
+            hir::ExprKind::Loop(_, Some(label), _) => {
                 self.labels.insert(label.ident.as_str(), expr.span);
             },
             _ => (),
index 3e3a5c48dabfc4602ee16fe111a6535057f887d7..a00eee67166ebcdf235f1cf25cd744a83b6c208e 100644 (file)
@@ -322,19 +322,6 @@ fn visit_expr(&mut self, expr: &Expr) {
                 self.current = cast_pat;
                 self.visit_expr(expr);
             },
-            ExprKind::While(ref cond, ref body, _) => {
-                let cond_pat = self.next("cond");
-                let body_pat = self.next("body");
-                let label_pat = self.next("label");
-                println!(
-                    "While(ref {}, ref {}, ref {}) = {};",
-                    cond_pat, body_pat, label_pat, current
-                );
-                self.current = cond_pat;
-                self.visit_expr(cond);
-                self.current = body_pat;
-                self.visit_block(body);
-            },
             ExprKind::Loop(ref body, _, desugaring) => {
                 let body_pat = self.next("body");
                 let des = loop_desugaring_name(desugaring);
@@ -696,6 +683,7 @@ fn desugaring_name(des: hir::MatchSource) -> String {
     match des {
         hir::MatchSource::ForLoopDesugar => "MatchSource::ForLoopDesugar".to_string(),
         hir::MatchSource::TryDesugar => "MatchSource::TryDesugar".to_string(),
+        hir::MatchSource::WhileDesugar => "MatchSource::WhileDesugar".to_string(),
         hir::MatchSource::WhileLetDesugar => "MatchSource::WhileLetDesugar".to_string(),
         hir::MatchSource::Normal => "MatchSource::Normal".to_string(),
         hir::MatchSource::IfLetDesugar { contains_else_clause } => format!(
@@ -714,6 +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::WhileLet => "LoopSource::WhileLet",
     }
 }
index 5b2d24a7cb347e53f9b3819a327d50aad73f9295..e9b5cee430e7cdb373c6dc0882f73981e67ef57f 100644 (file)
@@ -148,11 +148,6 @@ pub fn eq_expr(&mut self, left: &Expr, right: &Expr) -> bool {
             (&ExprKind::Tup(ref l_tup), &ExprKind::Tup(ref r_tup)) => self.eq_exprs(l_tup, r_tup),
             (&ExprKind::Unary(l_op, ref le), &ExprKind::Unary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re),
             (&ExprKind::Array(ref l), &ExprKind::Array(ref r)) => self.eq_exprs(l, r),
-            (&ExprKind::While(ref lc, ref lb, ref ll), &ExprKind::While(ref rc, ref rb, ref rl)) => {
-                self.eq_expr(lc, rc)
-                    && self.eq_block(lb, rb)
-                    && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
-            },
             (&ExprKind::DropTemps(ref le), &ExprKind::DropTemps(ref re)) => self.eq_expr(le, re),
             _ => false,
         }
@@ -524,13 +519,6 @@ pub fn hash_expr(&mut self, e: &Expr) {
                 lop.hash(&mut self.s);
                 self.hash_expr(le);
             },
-            ExprKind::While(ref cond, ref b, l) => {
-                self.hash_expr(cond);
-                self.hash_block(b);
-                if let Some(l) = l {
-                    self.hash_name(l.ident.name);
-                }
-            },
         }
     }
 
index 00edb4fafcb12bc5c5b45aa9f421bbc3ab452dc7..ea169481ac6b39bebee6482bf9ce8582d8fabdd1 100644 (file)
@@ -209,11 +209,6 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) {
             print_expr(cx, e, indent + 1);
             println!("{}target type: {:?}", ind, target);
         },
-        hir::ExprKind::While(ref cond, _, _) => {
-            println!("{}While", ind);
-            println!("{}condition:", ind);
-            print_expr(cx, cond, indent + 1);
-        },
         hir::ExprKind::Loop(..) => {
             println!("{}Loop", ind);
         },
index a9643a74085ec519830fd91dad5a63b46bc79e4c..0e45750e94df2327b41aeeb9d4b459acd25bc563 100644 (file)
@@ -113,7 +113,6 @@ fn hir_from_snippet(expr: &hir::Expr, snippet: Cow<'a, str>) -> Self {
             | hir::ExprKind::Ret(..)
             | hir::ExprKind::Struct(..)
             | hir::ExprKind::Tup(..)
-            | hir::ExprKind::While(..)
             | hir::ExprKind::DropTemps(_)
             | hir::ExprKind::Err => Sugg::NonParen(snippet),
             hir::ExprKind::Assign(..) => Sugg::BinOp(AssocOp::Assign, snippet),