Skip to content

Commit 1067641

Browse files
committed
lint: port keyword idents diagnostics
Signed-off-by: David Wood <[email protected]>
1 parent 10f2d3f commit 1067641

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

compiler/rustc_error_messages/locales/en-US/lint.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,6 @@ lint-builtin-ellipsis-inclusive-range-patterns = `...` range patterns are deprec
373373
.suggestion = use `..=` for an inclusive range
374374
375375
lint-builtin-unnameable-test-items = cannot test inner items
376+
377+
lint-builtin-keyword-idents = `{$kw}` is a keyword in the {$next} edition
378+
.suggestion = you can use a raw identifier to stay compatible

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_error_messages::FluentValue;
88
use rustc_lint_defs::{Applicability, LintExpectationId};
99
use rustc_span::edition::LATEST_STABLE_EDITION;
1010
use rustc_span::symbol::{Ident, Symbol};
11-
use rustc_span::{Span, DUMMY_SP};
11+
use rustc_span::{edition::Edition, Span, DUMMY_SP};
1212
use std::borrow::Cow;
1313
use std::fmt;
1414
use std::hash::{Hash, Hasher};
@@ -115,6 +115,12 @@ impl IntoDiagnosticArg for String {
115115
}
116116
}
117117

118+
impl IntoDiagnosticArg for Edition {
119+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
120+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
121+
}
122+
}
123+
118124
impl IntoDiagnosticArg for Symbol {
119125
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
120126
self.to_ident_string().into_diagnostic_arg()

compiler/rustc_lint/src/builtin.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,10 +2033,12 @@ impl KeywordIdents {
20332033
}
20342034

20352035
cx.struct_span_lint(KEYWORD_IDENTS, ident.span, |lint| {
2036-
lint.build(&format!("`{}` is a keyword in the {} edition", ident, next_edition))
2036+
lint.build(fluent::lint::builtin_keyword_idents)
2037+
.set_arg("kw", ident.clone())
2038+
.set_arg("next", next_edition)
20372039
.span_suggestion(
20382040
ident.span,
2039-
"you can use a raw identifier to stay compatible",
2041+
fluent::lint::suggestion,
20402042
format!("r#{}", ident),
20412043
Applicability::MachineApplicable,
20422044
)

0 commit comments

Comments
 (0)