]> git.lizzy.rs Git - rust.git/commitdiff
Fixing src/copies.rs and src/entries.rs by using ExprBlock(block) = then.node
authorEnrico Schmitz <enrico@schmitz.link>
Fri, 31 Mar 2017 21:36:45 +0000 (23:36 +0200)
committerEnrico Schmitz <es@mdtm.de>
Fri, 31 Mar 2017 21:36:45 +0000 (23:36 +0200)
clippy_lints/src/copies.rs
clippy_lints/src/entry.rs
clippy_lints/src/let_if_seq.rs

index 034ce24d6ea92c5aca73855aa51054f83850baf8..92d0445a4ce30213b3fd6761576e1e29b1753fa8 100644 (file)
@@ -223,13 +223,15 @@ fn lint_match_arms(cx: &LateContext, expr: &Expr) {
 /// `if a { c } else if b { d } else { e }`.
 fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
     let mut conds = SmallVector::new();
-    let mut blocks = SmallVector::new();
+    let mut blocks : SmallVector<&Block> = SmallVector::new();
 
     while let ExprIf(ref cond, ref then_expr, ref else_expr) = expr.node {
         conds.push(&**cond);
-        //FIXME
-        //blocks.push(&**then_expr);
-        //FIXME
+        if let ExprBlock(ref block) = then_expr.node {
+            blocks.push(&block);
+        } else {
+            panic!("ExprIf node is not an ExprBlock");
+        }
 
         if let Some(ref else_expr) = *else_expr {
             expr = else_expr;
@@ -241,9 +243,7 @@ fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
     // final `else {..}`
     if !blocks.is_empty() {
         if let ExprBlock(ref block) = expr.node {
-            //FIXME
-            //blocks.push(&**block);
-            //FIXME
+            blocks.push(&**block);
         }
     }
 
@@ -315,10 +315,10 @@ fn search_same<T, Hash, Eq>(exprs: &[T], hash: Hash, eq: Eq) -> Option<(&T, &T)>
         return None;
     } else if exprs.len() == 2 {
         return if eq(&exprs[0], &exprs[1]) {
-            Some((&exprs[0], &exprs[1]))
-        } else {
-            None
-        };
+                   Some((&exprs[0], &exprs[1]))
+               } else {
+                   None
+               };
     }
 
     let mut map: HashMap<_, Vec<&_>> = HashMap::with_capacity(exprs.len());
index 2f5707be5c02e641285eb6cc2bd45a8464699048..06e9268d22a183337e84fa8ada56e522c0b8ba2c 100644 (file)
@@ -46,7 +46,14 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
                 if let Some((ty, map, key)) = check_cond(cx, check) {
                     // in case of `if !m.contains_key(&k) { m.insert(k, v); }`
                     // we can give a better error message
-                    let sole_expr = else_block.is_none();
+                    let sole_expr =  {
+                        else_block.is_none() &&
+                        if let ExprBlock(ref then_block) = then_block.node {
+                            (then_block.expr.is_some() as usize) + then_block.stmts.len() == 1
+                        }  else {
+                            true
+                        }
+                    };
 
                     let mut visitor = InsertVisitor {
                         cx: cx,
index 1b25a5cbda2f1325bb091b880149b6916765961d..fc858464fc484b673e1eb2a8607f390c6f85e7b6 100644 (file)
@@ -69,7 +69,9 @@ fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) {
                 let hir::StmtExpr(ref if_, _) = expr.node,
                 let hir::ExprIf(ref cond, ref then, ref else_) = if_.node,
                 !used_in_expr(cx, def_id, cond),
-                !used_in_expr(cx, def_id, &**then),
+                !used_in_expr(cx, def_id, &*then),
+                let hir::ExprBlock(ref then) = then.node,
+                let Some(value) = check_assign(cx, def_id, &*then),
             ], {
                 let span = Span { lo: stmt.span.lo, hi: if_.span.hi, ctxt: NO_EXPANSION };
 
@@ -104,7 +106,7 @@ fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) {
                     mut=mutability,
                     name=name.node,
                     cond=snippet(cx, cond.span, "_"),
-                    then={ "" },
+                    then=if then.stmts.len() > 1 { " ..;" } else { "" },
                     else=if default_multi_stmts { " ..;" } else { "" },
                     value=snippet(cx, then.span, "<value>"),
                     default=snippet(cx, default.span, "<default>"),