Skip to content

Commit

Permalink
lint: port redundant semicolons diagnostics
Browse files Browse the repository at this point in the history
Signed-off-by: David Wood <david.wood@huawei.com>
  • Loading branch information
davidtwco committed Jun 30, 2022
1 parent 37588d6 commit 8e83656
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 10 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/lint.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,13 @@ lint-noop-method-call = call to `.{$method}()` on a reference in this situation
lint-pass-by-value = passing `{$ty}` by reference
.suggestion = try passing by value
lint-redundant-semicolons =
unnecessary trailing {$multiple ->
[true] semicolons
*[false] semicolon
}
.suggestion = remove {$multiple ->
[true] these semicolons
*[false] this semicolon
}
12 changes: 5 additions & 7 deletions compiler/rustc_lint/src/redundant_semicolon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{EarlyContext, EarlyLintPass, LintContext};
use rustc_ast::{Block, StmtKind};
use rustc_errors::Applicability;
use rustc_errors::{fluent, Applicability};
use rustc_span::Span;

declare_lint! {
Expand Down Expand Up @@ -49,12 +49,10 @@ fn maybe_lint_redundant_semis(cx: &EarlyContext<'_>, seq: &mut Option<(Span, boo
}

cx.struct_span_lint(REDUNDANT_SEMICOLONS, span, |lint| {
let (msg, rem) = if multiple {
("unnecessary trailing semicolons", "remove these semicolons")
} else {
("unnecessary trailing semicolon", "remove this semicolon")
};
lint.build(msg).span_suggestion(span, rem, "", Applicability::MaybeIncorrect).emit();
lint.build(fluent::lint::redundant_semicolons)
.set_arg("multiple", multiple)
.span_suggestion(span, fluent::lint::suggestion, "", Applicability::MaybeIncorrect)
.emit();
});
}
}

0 comments on commit 8e83656

Please sign in to comment.