Skip to content

Commit 0fb3021

Browse files
authored
Merge pull request #3496 from fkohlgrueber/macro-in-closure-in-if-cond
fix #3482 and add ui test for it
2 parents f935912 + a8a0b23 commit 0fb3021

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: clippy_lints/src/block_in_if_condition.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
7070
if let ExprKind::Closure(_, _, eid, _, _) = expr.node {
7171
let body = self.cx.tcx.hir.body(eid);
7272
let ex = &body.value;
73-
if matches!(ex.node, ExprKind::Block(_, _)) {
73+
if matches!(ex.node, ExprKind::Block(_, _)) && !in_macro(body.value.span) {
7474
self.found_block = Some(ex);
7575
return;
7676
}

Diff for: tests/ui/block_in_if_condition.rs

+8
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,11 @@ fn condition_is_unsafe_block() {
9898

9999
fn main() {
100100
}
101+
102+
fn macro_in_closure() {
103+
let option = Some(true);
104+
105+
if option.unwrap_or_else(|| unimplemented!()) {
106+
unimplemented!()
107+
}
108+
}

0 commit comments

Comments
 (0)