Skip to content

Commit 48e4bf1

Browse files
committed
lint: port non-ascii-idents diagnostics
Signed-off-by: David Wood <[email protected]>
1 parent c29e05e commit 48e4bf1

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,15 @@ lint-cstring-ptr = getting the inner pointer of a temporary `CString`
6060
.unwrap-label = this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
6161
.note = pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
6262
.help = for more information, see https://doc.rust-lang.org/reference/destructors.html
63+
64+
lint-identifier-non-ascii-char = identifier contains non-ASCII characters
65+
66+
lint-identifier-uncommon-codepoints = identifier contains uncommon Unicode codepoints
67+
68+
lint-confusable-identifier-pair = identifier pair considered confusable between `{$existing_sym}` and `{$sym}`
69+
.label = this is where the previous identifier occurred
70+
71+
lint-mixed-script-confusables =
72+
the usage of Script Group `{$set}` in this crate consists solely of mixed script confusables
73+
.includes-note = the usage includes {$includes}
74+
.note = please recheck to make sure their usages are indeed what you want

compiler/rustc_lint/src/non_ascii_idents.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{EarlyContext, EarlyLintPass, LintContext};
22
use rustc_ast as ast;
33
use rustc_data_structures::fx::FxHashMap;
4+
use rustc_errors::fluent;
45
use rustc_span::symbol::Symbol;
56

67
declare_lint! {
@@ -180,13 +181,13 @@ impl EarlyLintPass for NonAsciiIdents {
180181
}
181182
has_non_ascii_idents = true;
182183
cx.struct_span_lint(NON_ASCII_IDENTS, sp, |lint| {
183-
lint.build("identifier contains non-ASCII characters").emit();
184+
lint.build(fluent::lint::identifier_non_ascii_char).emit();
184185
});
185186
if check_uncommon_codepoints
186187
&& !symbol_str.chars().all(GeneralSecurityProfile::identifier_allowed)
187188
{
188189
cx.struct_span_lint(UNCOMMON_CODEPOINTS, sp, |lint| {
189-
lint.build("identifier contains uncommon Unicode codepoints").emit();
190+
lint.build(fluent::lint::identifier_uncommon_codepoints).emit();
190191
})
191192
}
192193
}
@@ -216,15 +217,11 @@ impl EarlyLintPass for NonAsciiIdents {
216217
.and_modify(|(existing_symbol, existing_span, existing_is_ascii)| {
217218
if !*existing_is_ascii || !is_ascii {
218219
cx.struct_span_lint(CONFUSABLE_IDENTS, sp, |lint| {
219-
lint.build(&format!(
220-
"identifier pair considered confusable between `{}` and `{}`",
221-
existing_symbol, symbol
222-
))
223-
.span_label(
224-
*existing_span,
225-
"this is where the previous identifier occurred",
226-
)
227-
.emit();
220+
lint.build(fluent::lint::confusable_identifier_pair)
221+
.set_arg("existing_sym", *existing_symbol)
222+
.set_arg("sym", symbol)
223+
.span_label(*existing_span, fluent::lint::label)
224+
.emit();
228225
});
229226
}
230227
if *existing_is_ascii && !is_ascii {
@@ -326,18 +323,20 @@ impl EarlyLintPass for NonAsciiIdents {
326323

327324
for ((sp, ch_list), script_set) in lint_reports {
328325
cx.struct_span_lint(MIXED_SCRIPT_CONFUSABLES, sp, |lint| {
329-
let message = format!(
330-
"the usage of Script Group `{}` in this crate consists solely of mixed script confusables",
331-
script_set);
332-
let mut note = "the usage includes ".to_string();
326+
let mut includes = String::new();
333327
for (idx, ch) in ch_list.into_iter().enumerate() {
334328
if idx != 0 {
335-
note += ", ";
329+
includes += ", ";
336330
}
337331
let char_info = format!("'{}' (U+{:04X})", ch, ch as u32);
338-
note += &char_info;
332+
includes += &char_info;
339333
}
340-
lint.build(&message).note(&note).note("please recheck to make sure their usages are indeed what you want").emit();
334+
lint.build(fluent::lint::mixed_script_confusables)
335+
.set_arg("set", script_set.to_string())
336+
.set_arg("includes", includes)
337+
.note(fluent::lint::includes_note)
338+
.note(fluent::lint::note)
339+
.emit();
341340
});
342341
}
343342
}

0 commit comments

Comments
 (0)