Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3f69c1b

Browse files
committed
migrate: non_ascii_idents.rs
1 parent 384010b commit 3f69c1b

File tree

2 files changed

+49
-35
lines changed

2 files changed

+49
-35
lines changed

compiler/rustc_lint/src/lints.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@ use rustc_span::{symbol::Ident, Span, Symbol};
66

77
use crate::LateContext;
88

9+
#[derive(LintDiagnostic)]
10+
#[diag(lint_identifier_non_ascii_char)]
11+
pub struct IdentifierNonAsciiChar;
12+
13+
#[derive(LintDiagnostic)]
14+
#[diag(lint_identifier_uncommon_codepoints)]
15+
pub struct IdentifierUncommonCodepoints;
16+
17+
#[derive(LintDiagnostic)]
18+
#[diag(lint_confusable_identifier_pair)]
19+
pub struct ConfusableIdentifierPair {
20+
pub existing_sym: Symbol,
21+
pub sym: Symbol,
22+
#[label]
23+
pub label: Span,
24+
}
25+
26+
#[derive(LintDiagnostic)]
27+
#[diag(lint_mixed_script_confusables)]
28+
#[note(includes_note)]
29+
#[note]
30+
pub struct MixedScriptConfusables {
31+
pub set: String,
32+
pub includes: String,
33+
}
34+
935
pub struct NonFmtPanicUnused {
1036
pub count: usize,
1137
pub suggestion: Option<Span>,

compiler/rustc_lint/src/non_ascii_idents.rs

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
3+
use crate::lints::{
4+
ConfusableIdentifierPair, IdentifierNonAsciiChar, IdentifierUncommonCodepoints,
5+
MixedScriptConfusables,
6+
};
17
use crate::{EarlyContext, EarlyLintPass, LintContext};
28
use rustc_ast as ast;
39
use rustc_data_structures::fx::FxHashMap;
4-
use rustc_errors::fluent;
510
use rustc_span::symbol::Symbol;
611

712
declare_lint! {
@@ -180,21 +185,11 @@ impl EarlyLintPass for NonAsciiIdents {
180185
continue;
181186
}
182187
has_non_ascii_idents = true;
183-
cx.struct_span_lint(
184-
NON_ASCII_IDENTS,
185-
sp,
186-
fluent::lint_identifier_non_ascii_char,
187-
|lint| lint,
188-
);
188+
cx.emit_spanned_lint(NON_ASCII_IDENTS, sp, IdentifierNonAsciiChar);
189189
if check_uncommon_codepoints
190190
&& !symbol_str.chars().all(GeneralSecurityProfile::identifier_allowed)
191191
{
192-
cx.struct_span_lint(
193-
UNCOMMON_CODEPOINTS,
194-
sp,
195-
fluent::lint_identifier_uncommon_codepoints,
196-
|lint| lint,
197-
)
192+
cx.emit_spanned_lint(UNCOMMON_CODEPOINTS, sp, IdentifierUncommonCodepoints);
198193
}
199194
}
200195

@@ -222,14 +217,13 @@ impl EarlyLintPass for NonAsciiIdents {
222217
.entry(skeleton_sym)
223218
.and_modify(|(existing_symbol, existing_span, existing_is_ascii)| {
224219
if !*existing_is_ascii || !is_ascii {
225-
cx.struct_span_lint(
220+
cx.emit_spanned_lint(
226221
CONFUSABLE_IDENTS,
227222
sp,
228-
fluent::lint_confusable_identifier_pair,
229-
|lint| {
230-
lint.set_arg("existing_sym", *existing_symbol)
231-
.set_arg("sym", symbol)
232-
.span_label(*existing_span, fluent::label)
223+
ConfusableIdentifierPair {
224+
existing_sym: *existing_symbol,
225+
sym: symbol,
226+
label: *existing_span,
233227
},
234228
);
235229
}
@@ -331,24 +325,18 @@ impl EarlyLintPass for NonAsciiIdents {
331325
}
332326

333327
for ((sp, ch_list), script_set) in lint_reports {
334-
cx.struct_span_lint(
328+
let mut includes = String::new();
329+
for (idx, ch) in ch_list.into_iter().enumerate() {
330+
if idx != 0 {
331+
includes += ", ";
332+
}
333+
let char_info = format!("'{}' (U+{:04X})", ch, ch as u32);
334+
includes += &char_info;
335+
}
336+
cx.emit_spanned_lint(
335337
MIXED_SCRIPT_CONFUSABLES,
336338
sp,
337-
fluent::lint_mixed_script_confusables,
338-
|lint| {
339-
let mut includes = String::new();
340-
for (idx, ch) in ch_list.into_iter().enumerate() {
341-
if idx != 0 {
342-
includes += ", ";
343-
}
344-
let char_info = format!("'{}' (U+{:04X})", ch, ch as u32);
345-
includes += &char_info;
346-
}
347-
lint.set_arg("set", script_set.to_string())
348-
.set_arg("includes", includes)
349-
.note(fluent::includes_note)
350-
.note(fluent::note)
351-
},
339+
MixedScriptConfusables { set: script_set.to_string(), includes },
352340
);
353341
}
354342
}

0 commit comments

Comments
 (0)