about summary refs log tree commit diff
diff options
context:
space:
mode:
authorxFrednet <xFrednet@gmail.com>2021-02-26 21:29:55 +0100
committerxFrednet <xFrednet@gmail.com>2021-04-05 13:35:51 +0200
commit8c0b4d7f65802031f0131bc56de8fb8b275d70d7 (patch)
tree1cb436450985e75a4b1f4741084eb6c108774290
parent617c65baa90cdbd9228cacad4f2079a9d868d070 (diff)
downloadrust-8c0b4d7f65802031f0131bc56de8fb8b275d70d7.tar.gz
rust-8c0b4d7f65802031f0131bc56de8fb8b275d70d7.zip
Only running shared_code_in_if_blocks only for if statements
-rw-r--r--clippy_lints/src/copies.rs32
1 files changed, 17 insertions, 15 deletions
diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs
index 8b94ac96880..ff99a9a09b3 100644
--- a/clippy_lints/src/copies.rs
+++ b/clippy_lints/src/copies.rs
@@ -156,23 +156,25 @@ declare_lint_pass!(CopyAndPaste => [
 impl<'tcx> LateLintPass<'tcx> for CopyAndPaste {
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
         if !expr.span.from_expansion() {
-            // skip ifs directly in else, it will be checked in the parent if
-            if let Some(&Expr {
-                kind: ExprKind::If(_, _, Some(ref else_expr)),
-                ..
-            }) = get_parent_expr(cx, expr)
-            {
-                if else_expr.hir_id == expr.hir_id {
-                    return;
+            if let ExprKind::If(_, _, _) = expr.kind {
+                // skip ifs directly in else, it will be checked in the parent if
+                if let Some(&Expr {
+                    kind: ExprKind::If(_, _, Some(ref else_expr)),
+                    ..
+                }) = get_parent_expr(cx, expr)
+                {
+                    if else_expr.hir_id == expr.hir_id {
+                        return;
+                    }
                 }
-            }
 
-            let (conds, blocks) = if_sequence(expr);
-            // Conditions
-            lint_same_cond(cx, &conds);
-            lint_same_fns_in_if_cond(cx, &conds);
-            // Block duplication
-            lint_same_then_else(cx, &blocks, conds.len() != blocks.len(), expr);
+                let (conds, blocks) = if_sequence(expr);
+                // Conditions
+                lint_same_cond(cx, &conds);
+                lint_same_fns_in_if_cond(cx, &conds);
+                // Block duplication
+                lint_same_then_else(cx, &blocks, conds.len() != blocks.len(), expr);
+            }
         }
     }
 }