1 use crate::{lints::RedundantSemicolonsDiag, EarlyContext, EarlyLintPass, LintContext};
2 use rustc_ast::{Block, StmtKind};
6 /// The `redundant_semicolons` lint detects unnecessary trailing
19 /// Extra semicolons are not needed, and may be removed to avoid confusion
20 /// and visual clutter.
21 pub REDUNDANT_SEMICOLONS,
23 "detects unnecessary trailing semicolons"
26 declare_lint_pass!(RedundantSemicolons => [REDUNDANT_SEMICOLONS]);
28 impl EarlyLintPass for RedundantSemicolons {
29 fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) {
31 for stmt in block.stmts.iter() {
32 match (&stmt.kind, &mut seq) {
33 (StmtKind::Empty, None) => seq = Some((stmt.span, false)),
34 (StmtKind::Empty, Some(seq)) => *seq = (seq.0.to(stmt.span), true),
35 (_, seq) => maybe_lint_redundant_semis(cx, seq),
38 maybe_lint_redundant_semis(cx, &mut seq);
42 fn maybe_lint_redundant_semis(cx: &EarlyContext<'_>, seq: &mut Option<(Span, bool)>) {
43 if let Some((span, multiple)) = seq.take() {
44 // FIXME: Find a better way of ignoring the trailing
45 // semicolon from macro expansion
46 if span == rustc_span::DUMMY_SP {
53 RedundantSemicolonsDiag { multiple, suggestion: span },