about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkyoto7250 <50972773+kyoto7250@users.noreply.github.com>2022-06-18 17:49:03 +0900
committerkyoto7250 <50972773+kyoto7250@users.noreply.github.com>2022-06-18 17:49:03 +0900
commit7a83809c8c63b135bf5d2d1c9e42d0a94ea5c5ad (patch)
treed6b68a2e946ff60b5233e745144216f88fdfe45b
parentf411c18a734a0c4d020ac578ccc3b5b8a7814f8f (diff)
downloadrust-7a83809c8c63b135bf5d2d1c9e42d0a94ea5c5ad.tar.gz
rust-7a83809c8c63b135bf5d2d1c9e42d0a94ea5c5ad.zip
check only first statement
-rw-r--r--clippy_lints/src/copies.rs12
-rw-r--r--tests/ui/if_same_then_else.rs32
2 files changed, 7 insertions, 37 deletions
diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs
index 673744d90b8..9b64d1631bd 100644
--- a/clippy_lints/src/copies.rs
+++ b/clippy_lints/src/copies.rs
@@ -372,11 +372,13 @@ fn eq_stmts(
 }
 
 fn contains_acceptable_macro(cx: &LateContext<'_>, block: &Block<'_>) -> bool {
-    for stmt in block.stmts {
-        match stmt.kind {
-            StmtKind::Semi(semi_expr) if acceptable_macro(cx, semi_expr) => return true,
-            _ => {},
-        }
+    if block.stmts.first().map_or(false, |stmt|
+        matches!(
+            stmt.kind,
+            StmtKind::Semi(semi_expr) if acceptable_macro(cx, semi_expr)
+        )
+    ) {
+        return true;
     }
 
     if let Some(block_expr) = block.expr
diff --git a/tests/ui/if_same_then_else.rs b/tests/ui/if_same_then_else.rs
index 2598c2ab426..4110d1a9c01 100644
--- a/tests/ui/if_same_then_else.rs
+++ b/tests/ui/if_same_then_else.rs
@@ -179,38 +179,6 @@ mod issue_8836 {
         } else {
             unimplemented!();
         }
-
-        if true {
-            println!("FOO");
-            todo!();
-        } else {
-            println!("FOO");
-            todo!();
-        }
-
-        if true {
-            println!("FOO");
-            unimplemented!();
-        } else {
-            println!("FOO");
-            unimplemented!();
-        }
-
-        if true {
-            println!("FOO");
-            todo!()
-        } else {
-            println!("FOO");
-            todo!()
-        }
-
-        if true {
-            println!("FOO");
-            unimplemented!()
-        } else {
-            println!("FOO");
-            unimplemented!()
-        }
     }
 }