Fix blocks_in_if_conditions false positive

This commit is contained in:
Caio 2021-12-08 20:02:28 -03:00
parent 07f4f7c2dd
commit 392b2eff4b
2 changed files with 13 additions and 3 deletions

View file

@ -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);

View file

@ -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;