lint: port keyword idents diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
10f2d3f566
commit
10676418fa
3 changed files with 14 additions and 3 deletions
|
@ -373,3 +373,6 @@ lint-builtin-ellipsis-inclusive-range-patterns = `...` range patterns are deprec
|
|||
.suggestion = use `..=` for an inclusive range
|
||||
|
||||
lint-builtin-unnameable-test-items = cannot test inner items
|
||||
|
||||
lint-builtin-keyword-idents = `{$kw}` is a keyword in the {$next} edition
|
||||
.suggestion = you can use a raw identifier to stay compatible
|
||||
|
|
|
@ -8,7 +8,7 @@ use rustc_error_messages::FluentValue;
|
|||
use rustc_lint_defs::{Applicability, LintExpectationId};
|
||||
use rustc_span::edition::LATEST_STABLE_EDITION;
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::{edition::Edition, Span, DUMMY_SP};
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
@ -115,6 +115,12 @@ impl IntoDiagnosticArg for String {
|
|||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for Edition {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for Symbol {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||
self.to_ident_string().into_diagnostic_arg()
|
||||
|
|
|
@ -2033,10 +2033,12 @@ impl KeywordIdents {
|
|||
}
|
||||
|
||||
cx.struct_span_lint(KEYWORD_IDENTS, ident.span, |lint| {
|
||||
lint.build(&format!("`{}` is a keyword in the {} edition", ident, next_edition))
|
||||
lint.build(fluent::lint::builtin_keyword_idents)
|
||||
.set_arg("kw", ident.clone())
|
||||
.set_arg("next", next_edition)
|
||||
.span_suggestion(
|
||||
ident.span,
|
||||
"you can use a raw identifier to stay compatible",
|
||||
fluent::lint::suggestion,
|
||||
format!("r#{}", ident),
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue