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