Skip to content

Commit aa3648a

Browse files
committed
Auto merge of rust-lang#8100 - c410-f3r:blah-blah-blah, r=giraffate
Fix `blocks_in_if_conditions` false positive Fix rust-lang#8099 changelog: Fix [`blocks_in_if_conditions`] false positive with an empty closure
2 parents d27f598 + 392b2ef commit aa3648a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

clippy_lints/src/blocks_in_if_conditions.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
7373

7474
let body = self.cx.tcx.hir().body(eid);
7575
let ex = &body.value;
76-
if matches!(ex.kind, ExprKind::Block(_, _)) && !body.value.span.from_expansion() {
77-
self.found_block = Some(ex);
78-
return;
76+
if let ExprKind::Block(block, _) = ex.kind {
77+
if !body.value.span.from_expansion() && !block.stmts.is_empty() {
78+
self.found_block = Some(ex);
79+
return;
80+
}
7981
}
8082
}
8183
walk_expr(self, expr);

tests/ui/blocks_in_if_conditions_closure.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ fn macro_in_closure() {
4444
}
4545
}
4646

47+
fn closure(_: impl FnMut()) -> bool {
48+
true
49+
}
50+
51+
fn function_with_empty_closure() {
52+
if closure(|| {}) {}
53+
}
54+
4755
#[rustfmt::skip]
4856
fn main() {
4957
let mut range = 0..10;

0 commit comments

Comments
 (0)