Skip to content

Commit 7e404e3

Browse files
committed
Fixed error with if blocks
1 parent 7667b9c commit 7e404e3

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

clippy_lints/src/semicolon_outside_block.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@ impl LateLintPass<'_> for SemicolonOutsideBlock {
4848
then {
4949
// make sure that the block does not belong to a function
5050
for (hir_id, _) in cx.tcx.hir().parent_iter(block.hir_id) {
51-
if_chain! {
52-
if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(hir_id);
53-
if let BodyOwnerKind::Fn = cx.tcx.hir().body_owner_kind(hir_id);
54-
let item_body = cx.tcx.hir().body(body_id);
55-
if let ExprKind::Block(fn_block, _) = item_body.value.kind;
56-
if fn_block.hir_id == block.hir_id;
57-
then { return }
51+
if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(hir_id) {
52+
if let BodyOwnerKind::Fn = cx.tcx.hir().body_owner_kind(hir_id) {
53+
let item_body = cx.tcx.hir().body(body_id);
54+
if let ExprKind::Block(fn_block, _) = item_body.value.kind {
55+
if let Some(pot_if) = fn_block.expr {
56+
if let ExprKind::If(..) = pot_if.kind {
57+
return;
58+
}
59+
}
60+
if fn_block.hir_id == block.hir_id {
61+
return
62+
}
63+
}
64+
}
5865
}
5966
}
6067
// filter out other blocks and the desugared for loop

tests/ui/semicolon_outside_block.rs

+8
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,11 @@ fn my_own_block() {
6161
fn just_get_unit() {
6262
get_unit();
6363
}
64+
65+
fn test_if() {
66+
if 1 > 2 {
67+
get_unit();
68+
} else {
69+
println!("everything alright!");
70+
}
71+
}

0 commit comments

Comments
 (0)