Skip to content

Commit

Permalink
Fixed error with if blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
1c3t3a committed Aug 13, 2021
1 parent 7667b9c commit 7e404e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
21 changes: 14 additions & 7 deletions clippy_lints/src/semicolon_outside_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,20 @@ impl LateLintPass<'_> for SemicolonOutsideBlock {
then {
// make sure that the block does not belong to a function
for (hir_id, _) in cx.tcx.hir().parent_iter(block.hir_id) {
if_chain! {
if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(hir_id);
if let BodyOwnerKind::Fn = cx.tcx.hir().body_owner_kind(hir_id);
let item_body = cx.tcx.hir().body(body_id);
if let ExprKind::Block(fn_block, _) = item_body.value.kind;
if fn_block.hir_id == block.hir_id;
then { return }
if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(hir_id) {
if let BodyOwnerKind::Fn = cx.tcx.hir().body_owner_kind(hir_id) {
let item_body = cx.tcx.hir().body(body_id);
if let ExprKind::Block(fn_block, _) = item_body.value.kind {
if let Some(pot_if) = fn_block.expr {
if let ExprKind::If(..) = pot_if.kind {
return;
}
}
if fn_block.hir_id == block.hir_id {
return
}
}
}
}
}
// filter out other blocks and the desugared for loop
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/semicolon_outside_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ fn my_own_block() {
fn just_get_unit() {
get_unit();
}

fn test_if() {
if 1 > 2 {
get_unit();
} else {
println!("everything alright!");
}
}

0 comments on commit 7e404e3

Please sign in to comment.