Auto merge of #8100 - c410-f3r:blah-blah-blah, r=giraffate

Fix `blocks_in_if_conditions` false positive

Fix #8099

changelog: Fix [`blocks_in_if_conditions`] false positive with an empty closure
This commit is contained in:
bors 2021-12-09 23:50:02 +00:00
commit aa3648af50
2 changed files with 13 additions and 3 deletions

View File

@ -73,9 +73,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;