|
1 | 1 | use crate::{EarlyContext, EarlyLintPass, LintContext};
|
2 | 2 | use rustc_ast as ast;
|
3 | 3 | use rustc_data_structures::fx::FxHashMap;
|
| 4 | +use rustc_errors::fluent; |
4 | 5 | use rustc_span::symbol::Symbol;
|
5 | 6 |
|
6 | 7 | declare_lint! {
|
@@ -180,13 +181,13 @@ impl EarlyLintPass for NonAsciiIdents {
|
180 | 181 | }
|
181 | 182 | has_non_ascii_idents = true;
|
182 | 183 | 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(); |
184 | 185 | });
|
185 | 186 | if check_uncommon_codepoints
|
186 | 187 | && !symbol_str.chars().all(GeneralSecurityProfile::identifier_allowed)
|
187 | 188 | {
|
188 | 189 | 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(); |
190 | 191 | })
|
191 | 192 | }
|
192 | 193 | }
|
@@ -216,15 +217,11 @@ impl EarlyLintPass for NonAsciiIdents {
|
216 | 217 | .and_modify(|(existing_symbol, existing_span, existing_is_ascii)| {
|
217 | 218 | if !*existing_is_ascii || !is_ascii {
|
218 | 219 | 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(); |
228 | 225 | });
|
229 | 226 | }
|
230 | 227 | if *existing_is_ascii && !is_ascii {
|
@@ -326,18 +323,20 @@ impl EarlyLintPass for NonAsciiIdents {
|
326 | 323 |
|
327 | 324 | for ((sp, ch_list), script_set) in lint_reports {
|
328 | 325 | 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(); |
333 | 327 | for (idx, ch) in ch_list.into_iter().enumerate() {
|
334 | 328 | if idx != 0 {
|
335 |
| - note += ", "; |
| 329 | + includes += ", "; |
336 | 330 | }
|
337 | 331 | let char_info = format!("'{}' (U+{:04X})", ch, ch as u32);
|
338 |
| - note += &char_info; |
| 332 | + includes += &char_info; |
339 | 333 | }
|
340 |
| - lint.build(&message).note(¬e).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(); |
341 | 340 | });
|
342 | 341 | }
|
343 | 342 | }
|
|
0 commit comments