Skip to content

Commit 6ada445

Browse files
committed
Lint on redundant trailing semicolon after item
We now lint on code like this: ```rust fn main() { fn foo() {}; struct Bar {}; } ``` Previously, this caused warnings in Cargo, so it was disabled.
1 parent 3d6705a commit 6ada445

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

compiler/rustc_lint/src/redundant_semicolon.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,26 @@ 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;
3231
let mut seq = None;
3332
for stmt in block.stmts.iter() {
3433
match (&stmt.kind, &mut seq) {
3534
(StmtKind::Empty, None) => seq = Some((stmt.span, false)),
3635
(StmtKind::Empty, Some(seq)) => *seq = (seq.0.to(stmt.span), true),
37-
(_, seq) => {
38-
maybe_lint_redundant_semis(cx, seq, after_item_stmt);
39-
after_item_stmt = matches!(stmt.kind, StmtKind::Item(_));
40-
}
36+
(_, seq) => maybe_lint_redundant_semis(cx, seq),
4137
}
4238
}
43-
maybe_lint_redundant_semis(cx, &mut seq, after_item_stmt);
39+
maybe_lint_redundant_semis(cx, &mut seq);
4440
}
4541
}
4642

47-
fn maybe_lint_redundant_semis(
48-
cx: &EarlyContext<'_>,
49-
seq: &mut Option<(Span, bool)>,
50-
after_item_stmt: bool,
51-
) {
43+
fn maybe_lint_redundant_semis(cx: &EarlyContext<'_>, seq: &mut Option<(Span, bool)>) {
5244
if let Some((span, multiple)) = seq.take() {
5345
// FIXME: Find a better way of ignoring the trailing
5446
// semicolon from macro expansion
5547
if span == rustc_span::DUMMY_SP {
5648
return;
5749
}
5850

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-
6551
cx.struct_span_lint(REDUNDANT_SEMICOLONS, span, |lint| {
6652
let (msg, rem) = if multiple {
6753
("unnecessary trailing semicolons", "remove these semicolons")
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
// check-pass
2-
// This test should stop compiling
3-
// we decide to enable this lint for item statements.
4-
51
#![deny(redundant_semicolons)]
62

73
fn main() {
8-
fn inner() {};
9-
struct Bar {};
4+
fn inner() {}; //~ ERROR unnecessary
5+
struct Bar {}; //~ ERROR unnecessary
106
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: unnecessary trailing semicolon
2+
--> $DIR/item-stmt-semi.rs:4:18
3+
|
4+
LL | fn inner() {};
5+
| ^ help: remove this semicolon
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/item-stmt-semi.rs:1:9
9+
|
10+
LL | #![deny(redundant_semicolons)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: unnecessary trailing semicolon
14+
--> $DIR/item-stmt-semi.rs:5:18
15+
|
16+
LL | struct Bar {};
17+
| ^ help: remove this semicolon
18+
19+
error: aborting due to 2 previous errors
20+

0 commit comments

Comments
 (0)