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.
This commit is contained in:
parent
e8564ad589
commit
772292fa51
@ -28,25 +28,40 @@ declare_lint_pass!(RedundantSemicolons => [REDUNDANT_SEMICOLONS]);
|
||||
|
||||
impl EarlyLintPass for RedundantSemicolons {
|
||||
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) {
|
||||
let mut after_item_stmt = false;
|
||||
let mut seq = None;
|
||||
for stmt in block.stmts.iter() {
|
||||
match (&stmt.kind, &mut seq) {
|
||||
(StmtKind::Empty, None) => seq = Some((stmt.span, false)),
|
||||
(StmtKind::Empty, Some(seq)) => *seq = (seq.0.to(stmt.span), true),
|
||||
(_, seq) => maybe_lint_redundant_semis(cx, seq),
|
||||
(_, seq) => {
|
||||
maybe_lint_redundant_semis(cx, seq, after_item_stmt);
|
||||
after_item_stmt = matches!(stmt.kind, StmtKind::Item(_));
|
||||
}
|
||||
}
|
||||
}
|
||||
maybe_lint_redundant_semis(cx, &mut seq);
|
||||
maybe_lint_redundant_semis(cx, &mut seq, after_item_stmt);
|
||||
}
|
||||
}
|
||||
|
||||
fn maybe_lint_redundant_semis(cx: &EarlyContext<'_>, seq: &mut Option<(Span, bool)>) {
|
||||
fn maybe_lint_redundant_semis(
|
||||
cx: &EarlyContext<'_>,
|
||||
seq: &mut Option<(Span, bool)>,
|
||||
after_item_stmt: bool,
|
||||
) {
|
||||
if let Some((span, multiple)) = seq.take() {
|
||||
// FIXME: Find a better way of ignoring the trailing
|
||||
// semicolon from macro expansion
|
||||
if span == rustc_span::DUMMY_SP {
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: Lint on semicolons after item statements
|
||||
// once doing so doesn't break bootstrapping
|
||||
if after_item_stmt {
|
||||
return;
|
||||
}
|
||||
|
||||
cx.struct_span_lint(REDUNDANT_SEMICOLONS, span, |lint| {
|
||||
let (msg, rem) = if multiple {
|
||||
("unnecessary trailing semicolons", "remove these semicolons")
|
||||
|
10
src/test/ui/lint/redundant-semicolon/item-stmt-semi.rs
Normal file
10
src/test/ui/lint/redundant-semicolon/item-stmt-semi.rs
Normal file
@ -0,0 +1,10 @@
|
||||
// check-pass
|
||||
// This test should stop compiling
|
||||
// we decide to enable this lint for item statements.
|
||||
|
||||
#![deny(redundant_semicolons)]
|
||||
|
||||
fn main() {
|
||||
fn inner() {};
|
||||
struct Bar {};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user