Skip to content

Commit 772292f

Browse files
committed
Don't lint on redundant semicolons after item statements
This preserves the current lint behavior for now. Linting after item statements currently prevents the compiler from bootstrapping. Fixing this is blocked on fixing this upstream in Cargo, and bumping the Cargo submodule.
1 parent e8564ad commit 772292f

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

compiler/rustc_lint/src/redundant_semicolon.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,40 @@ declare_lint_pass!(RedundantSemicolons => [REDUNDANT_SEMICOLONS]);
2828

2929
impl EarlyLintPass for RedundantSemicolons {
3030
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) {
31+
let mut after_item_stmt = false;
3132
let mut seq = None;
3233
for stmt in block.stmts.iter() {
3334
match (&stmt.kind, &mut seq) {
3435
(StmtKind::Empty, None) => seq = Some((stmt.span, false)),
3536
(StmtKind::Empty, Some(seq)) => *seq = (seq.0.to(stmt.span), true),
36-
(_, seq) => maybe_lint_redundant_semis(cx, seq),
37+
(_, seq) => {
38+
maybe_lint_redundant_semis(cx, seq, after_item_stmt);
39+
after_item_stmt = matches!(stmt.kind, StmtKind::Item(_));
40+
}
3741
}
3842
}
39-
maybe_lint_redundant_semis(cx, &mut seq);
43+
maybe_lint_redundant_semis(cx, &mut seq, after_item_stmt);
4044
}
4145
}
4246

43-
fn maybe_lint_redundant_semis(cx: &EarlyContext<'_>, seq: &mut Option<(Span, bool)>) {
47+
fn maybe_lint_redundant_semis(
48+
cx: &EarlyContext<'_>,
49+
seq: &mut Option<(Span, bool)>,
50+
after_item_stmt: bool,
51+
) {
4452
if let Some((span, multiple)) = seq.take() {
4553
// FIXME: Find a better way of ignoring the trailing
4654
// semicolon from macro expansion
4755
if span == rustc_span::DUMMY_SP {
4856
return;
4957
}
58+
59+
// FIXME: Lint on semicolons after item statements
60+
// once doing so doesn't break bootstrapping
61+
if after_item_stmt {
62+
return;
63+
}
64+
5065
cx.struct_span_lint(REDUNDANT_SEMICOLONS, span, |lint| {
5166
let (msg, rem) = if multiple {
5267
("unnecessary trailing semicolons", "remove these semicolons")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// check-pass
2+
// This test should stop compiling
3+
// we decide to enable this lint for item statements.
4+
5+
#![deny(redundant_semicolons)]
6+
7+
fn main() {
8+
fn inner() {};
9+
struct Bar {};
10+
}

0 commit comments

Comments
 (0)