1 use crate::{EarlyContext, EarlyLintPass, LintContext}
;
2 use rustc_ast
::{Block, StmtKind}
;
3 use rustc_errors
::Applicability
;
7 /// The `redundant_semicolons` lint detects unnecessary trailing
20 /// Extra semicolons are not needed, and may be removed to avoid confusion
21 /// and visual clutter.
22 pub REDUNDANT_SEMICOLONS
,
24 "detects unnecessary trailing semicolons"
27 declare_lint_pass
!(RedundantSemicolons
=> [REDUNDANT_SEMICOLONS
]);
29 impl EarlyLintPass
for RedundantSemicolons
{
30 fn check_block(&mut self, cx
: &EarlyContext
<'_
>, block
: &Block
) {
32 for stmt
in block
.stmts
.iter() {
33 match (&stmt
.kind
, &mut seq
) {
34 (StmtKind
::Empty
, None
) => seq
= Some((stmt
.span
, false)),
35 (StmtKind
::Empty
, Some(seq
)) => *seq
= (seq
.0.to(stmt
.span
), true),
36 (_
, seq
) => maybe_lint_redundant_semis(cx
, seq
),
39 maybe_lint_redundant_semis(cx
, &mut seq
);
43 fn maybe_lint_redundant_semis(cx
: &EarlyContext
<'_
>, seq
: &mut Option
<(Span
, bool
)>) {
44 if let Some((span
, multiple
)) = seq
.take() {
45 // FIXME: Find a better way of ignoring the trailing
46 // semicolon from macro expansion
47 if span
== rustc_span
::DUMMY_SP
{
51 cx
.struct_span_lint(REDUNDANT_SEMICOLONS
, span
, |lint
| {
52 let (msg
, rem
) = if multiple
{
53 ("unnecessary trailing semicolons", "remove these semicolons")
55 ("unnecessary trailing semicolon", "remove this semicolon")
57 lint
.build(msg
).span_suggestion(span
, rem
, "", Applicability
::MaybeIncorrect
).emit();