Skip to content

Commit 2b9fb32

Browse files
clean-up semicolon_inside_block (#15390)
changelog: none
2 parents 470ee4f + 1fc5e81 commit 2b9fb32

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

clippy_lints/src/semicolon_block.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl SemicolonBlock {
102102
}
103103

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

107107
// For macro call semicolon statements (`mac!();`), the statement's span does not actually
108108
// include the semicolon itself, so use `mac_call_stmt_semi_span`, which finds the semicolon
@@ -144,38 +144,26 @@ impl LateLintPass<'_> for SemicolonBlock {
144144
kind: ExprKind::Block(block, _),
145145
..
146146
}) if !block.span.from_expansion() && stmt.span.contains(block.span) => {
147-
let Block {
148-
expr: None,
149-
stmts: [.., stmt],
150-
..
151-
} = block
152-
else {
153-
return;
154-
};
155-
let &Stmt {
156-
kind: StmtKind::Semi(expr),
157-
..
158-
} = stmt
159-
else {
160-
return;
161-
};
162-
self.semicolon_outside_block(cx, block, expr);
147+
if block.expr.is_none()
148+
&& let [.., stmt] = block.stmts
149+
&& let StmtKind::Semi(expr) = stmt.kind
150+
{
151+
self.semicolon_outside_block(cx, block, expr);
152+
}
163153
},
164154
StmtKind::Semi(Expr {
165-
kind: ExprKind::Block(block @ Block { expr: Some(tail), .. }, _),
155+
kind: ExprKind::Block(block, _),
166156
..
167157
}) if !block.span.from_expansion() => {
168-
self.semicolon_inside_block(cx, block, tail, stmt.span);
158+
if let Some(tail) = block.expr {
159+
self.semicolon_inside_block(cx, block, tail, stmt.span);
160+
}
169161
},
170162
_ => (),
171163
}
172164
}
173165
}
174166

175167
fn get_line(cx: &LateContext<'_>, span: Span) -> Option<usize> {
176-
if let Ok(line) = cx.sess().source_map().lookup_line(span.lo()) {
177-
return Some(line.line);
178-
}
179-
180-
None
168+
cx.sess().source_map().lookup_line(span.lo()).ok().map(|line| line.line)
181169
}

0 commit comments

Comments
 (0)