migrate: non_ascii_idents.rs
This commit is contained in:
parent
384010b9f4
commit
3f69c1b523
2 changed files with 49 additions and 35 deletions
|
@ -6,6 +6,32 @@ use rustc_span::{symbol::Ident, Span, Symbol};
|
||||||
|
|
||||||
use crate::LateContext;
|
use crate::LateContext;
|
||||||
|
|
||||||
|
#[derive(LintDiagnostic)]
|
||||||
|
#[diag(lint_identifier_non_ascii_char)]
|
||||||
|
pub struct IdentifierNonAsciiChar;
|
||||||
|
|
||||||
|
#[derive(LintDiagnostic)]
|
||||||
|
#[diag(lint_identifier_uncommon_codepoints)]
|
||||||
|
pub struct IdentifierUncommonCodepoints;
|
||||||
|
|
||||||
|
#[derive(LintDiagnostic)]
|
||||||
|
#[diag(lint_confusable_identifier_pair)]
|
||||||
|
pub struct ConfusableIdentifierPair {
|
||||||
|
pub existing_sym: Symbol,
|
||||||
|
pub sym: Symbol,
|
||||||
|
#[label]
|
||||||
|
pub label: Span,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(LintDiagnostic)]
|
||||||
|
#[diag(lint_mixed_script_confusables)]
|
||||||
|
#[note(includes_note)]
|
||||||
|
#[note]
|
||||||
|
pub struct MixedScriptConfusables {
|
||||||
|
pub set: String,
|
||||||
|
pub includes: String,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct NonFmtPanicUnused {
|
pub struct NonFmtPanicUnused {
|
||||||
pub count: usize,
|
pub count: usize,
|
||||||
pub suggestion: Option<Span>,
|
pub suggestion: Option<Span>,
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
|
use crate::lints::{
|
||||||
|
ConfusableIdentifierPair, IdentifierNonAsciiChar, IdentifierUncommonCodepoints,
|
||||||
|
MixedScriptConfusables,
|
||||||
|
};
|
||||||
use crate::{EarlyContext, EarlyLintPass, LintContext};
|
use crate::{EarlyContext, EarlyLintPass, LintContext};
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::fluent;
|
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
|
@ -180,21 +185,11 @@ impl EarlyLintPass for NonAsciiIdents {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
has_non_ascii_idents = true;
|
has_non_ascii_idents = true;
|
||||||
cx.struct_span_lint(
|
cx.emit_spanned_lint(NON_ASCII_IDENTS, sp, IdentifierNonAsciiChar);
|
||||||
NON_ASCII_IDENTS,
|
|
||||||
sp,
|
|
||||||
fluent::lint_identifier_non_ascii_char,
|
|
||||||
|lint| lint,
|
|
||||||
);
|
|
||||||
if check_uncommon_codepoints
|
if check_uncommon_codepoints
|
||||||
&& !symbol_str.chars().all(GeneralSecurityProfile::identifier_allowed)
|
&& !symbol_str.chars().all(GeneralSecurityProfile::identifier_allowed)
|
||||||
{
|
{
|
||||||
cx.struct_span_lint(
|
cx.emit_spanned_lint(UNCOMMON_CODEPOINTS, sp, IdentifierUncommonCodepoints);
|
||||||
UNCOMMON_CODEPOINTS,
|
|
||||||
sp,
|
|
||||||
fluent::lint_identifier_uncommon_codepoints,
|
|
||||||
|lint| lint,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,14 +217,13 @@ impl EarlyLintPass for NonAsciiIdents {
|
||||||
.entry(skeleton_sym)
|
.entry(skeleton_sym)
|
||||||
.and_modify(|(existing_symbol, existing_span, existing_is_ascii)| {
|
.and_modify(|(existing_symbol, existing_span, existing_is_ascii)| {
|
||||||
if !*existing_is_ascii || !is_ascii {
|
if !*existing_is_ascii || !is_ascii {
|
||||||
cx.struct_span_lint(
|
cx.emit_spanned_lint(
|
||||||
CONFUSABLE_IDENTS,
|
CONFUSABLE_IDENTS,
|
||||||
sp,
|
sp,
|
||||||
fluent::lint_confusable_identifier_pair,
|
ConfusableIdentifierPair {
|
||||||
|lint| {
|
existing_sym: *existing_symbol,
|
||||||
lint.set_arg("existing_sym", *existing_symbol)
|
sym: symbol,
|
||||||
.set_arg("sym", symbol)
|
label: *existing_span,
|
||||||
.span_label(*existing_span, fluent::label)
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -331,11 +325,6 @@ impl EarlyLintPass for NonAsciiIdents {
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((sp, ch_list), script_set) in lint_reports {
|
for ((sp, ch_list), script_set) in lint_reports {
|
||||||
cx.struct_span_lint(
|
|
||||||
MIXED_SCRIPT_CONFUSABLES,
|
|
||||||
sp,
|
|
||||||
fluent::lint_mixed_script_confusables,
|
|
||||||
|lint| {
|
|
||||||
let mut includes = String::new();
|
let mut includes = String::new();
|
||||||
for (idx, ch) in ch_list.into_iter().enumerate() {
|
for (idx, ch) in ch_list.into_iter().enumerate() {
|
||||||
if idx != 0 {
|
if idx != 0 {
|
||||||
|
@ -344,11 +333,10 @@ impl EarlyLintPass for NonAsciiIdents {
|
||||||
let char_info = format!("'{}' (U+{:04X})", ch, ch as u32);
|
let char_info = format!("'{}' (U+{:04X})", ch, ch as u32);
|
||||||
includes += &char_info;
|
includes += &char_info;
|
||||||
}
|
}
|
||||||
lint.set_arg("set", script_set.to_string())
|
cx.emit_spanned_lint(
|
||||||
.set_arg("includes", includes)
|
MIXED_SCRIPT_CONFUSABLES,
|
||||||
.note(fluent::includes_note)
|
sp,
|
||||||
.note(fluent::note)
|
MixedScriptConfusables { set: script_set.to_string(), includes },
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue