Skip to content

Commit

Permalink
Fix blocks_in_if_conditions false positive
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed Dec 8, 2021
1 parent 07f4f7c commit 392b2ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions clippy_lints/src/blocks_in_if_conditions.rs
Expand Up @@ -72,9 +72,11 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {

let body = self.cx.tcx.hir().body(eid);
let ex = &body.value;
if matches!(ex.kind, ExprKind::Block(_, _)) && !body.value.span.from_expansion() {
self.found_block = Some(ex);
return;
if let ExprKind::Block(block, _) = ex.kind {
if !body.value.span.from_expansion() && !block.stmts.is_empty() {
self.found_block = Some(ex);
return;
}
}
}
walk_expr(self, expr);
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/blocks_in_if_conditions_closure.rs
Expand Up @@ -44,6 +44,14 @@ fn macro_in_closure() {
}
}

fn closure(_: impl FnMut()) -> bool {
true
}

fn function_with_empty_closure() {
if closure(|| {}) {}
}

#[rustfmt::skip]
fn main() {
let mut range = 0..10;
Expand Down

0 comments on commit 392b2ef

Please sign in to comment.