Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions clippy_lints/src/semicolon_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl SemicolonBlock {
}

fn semicolon_outside_block(&self, cx: &LateContext<'_>, block: &Block<'_>, tail_stmt_expr: &Expr<'_>) {
let insert_span = block.span.with_lo(block.span.hi());
let insert_span = block.span.shrink_to_hi();

// For macro call semicolon statements (`mac!();`), the statement's span does not actually
// include the semicolon itself, so use `mac_call_stmt_semi_span`, which finds the semicolon
Expand Down Expand Up @@ -144,38 +144,26 @@ impl LateLintPass<'_> for SemicolonBlock {
kind: ExprKind::Block(block, _),
..
}) if !block.span.from_expansion() && stmt.span.contains(block.span) => {
let Block {
expr: None,
stmts: [.., stmt],
..
} = block
else {
return;
};
let &Stmt {
kind: StmtKind::Semi(expr),
..
} = stmt
else {
return;
};
self.semicolon_outside_block(cx, block, expr);
if block.expr.is_none()
&& let [.., stmt] = block.stmts
&& let StmtKind::Semi(expr) = stmt.kind
{
self.semicolon_outside_block(cx, block, expr);
}
},
StmtKind::Semi(Expr {
kind: ExprKind::Block(block @ Block { expr: Some(tail), .. }, _),
kind: ExprKind::Block(block, _),
..
}) if !block.span.from_expansion() => {
self.semicolon_inside_block(cx, block, tail, stmt.span);
if let Some(tail) = block.expr {
self.semicolon_inside_block(cx, block, tail, stmt.span);
}
},
_ => (),
}
}
}

fn get_line(cx: &LateContext<'_>, span: Span) -> Option<usize> {
if let Ok(line) = cx.sess().source_map().lookup_line(span.lo()) {
return Some(line.line);
}

None
cx.sess().source_map().lookup_line(span.lo()).ok().map(|line| line.line)
}