Skip to content

Commit 7a83809

Browse files
committed
check only first statement
1 parent f411c18 commit 7a83809

File tree

2 files changed

+7
-37
lines changed

2 files changed

+7
-37
lines changed

clippy_lints/src/copies.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,13 @@ fn eq_stmts(
372372
}
373373

374374
fn contains_acceptable_macro(cx: &LateContext<'_>, block: &Block<'_>) -> bool {
375-
for stmt in block.stmts {
376-
match stmt.kind {
377-
StmtKind::Semi(semi_expr) if acceptable_macro(cx, semi_expr) => return true,
378-
_ => {},
379-
}
375+
if block.stmts.first().map_or(false, |stmt|
376+
matches!(
377+
stmt.kind,
378+
StmtKind::Semi(semi_expr) if acceptable_macro(cx, semi_expr)
379+
)
380+
) {
381+
return true;
380382
}
381383

382384
if let Some(block_expr) = block.expr

tests/ui/if_same_then_else.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -179,38 +179,6 @@ mod issue_8836 {
179179
} else {
180180
unimplemented!();
181181
}
182-
183-
if true {
184-
println!("FOO");
185-
todo!();
186-
} else {
187-
println!("FOO");
188-
todo!();
189-
}
190-
191-
if true {
192-
println!("FOO");
193-
unimplemented!();
194-
} else {
195-
println!("FOO");
196-
unimplemented!();
197-
}
198-
199-
if true {
200-
println!("FOO");
201-
todo!()
202-
} else {
203-
println!("FOO");
204-
todo!()
205-
}
206-
207-
if true {
208-
println!("FOO");
209-
unimplemented!()
210-
} else {
211-
println!("FOO");
212-
unimplemented!()
213-
}
214182
}
215183
}
216184

0 commit comments

Comments
 (0)