1 use crate::{EarlyContext, EarlyLintPass, LintContext};
2 use rustc_ast::ast::{Block, StmtKind};
3 use rustc_errors::Applicability;
7 pub REDUNDANT_SEMICOLONS,
9 "detects unnecessary trailing semicolons"
12 declare_lint_pass!(RedundantSemicolons => [REDUNDANT_SEMICOLONS]);
14 impl EarlyLintPass for RedundantSemicolons {
15 fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) {
17 for stmt in block.stmts.iter() {
18 match (&stmt.kind, &mut seq) {
19 (StmtKind::Empty, None) => seq = Some((stmt.span, false)),
20 (StmtKind::Empty, Some(seq)) => *seq = (seq.0.to(stmt.span), true),
21 (_, seq) => maybe_lint_redundant_semis(cx, seq),
24 maybe_lint_redundant_semis(cx, &mut seq);
28 fn maybe_lint_redundant_semis(cx: &EarlyContext<'_>, seq: &mut Option<(Span, bool)>) {
29 if let Some((span, multiple)) = seq.take() {
30 cx.struct_span_lint(REDUNDANT_SEMICOLONS, span, |lint| {
31 let (msg, rem) = if multiple {
32 ("unnecessary trailing semicolons", "remove these semicolons")
34 ("unnecessary trailing semicolon", "remove this semicolon")
37 .span_suggestion(span, rem, String::new(), Applicability::MaybeIncorrect)