add list of characters to uncommon codepoints lint

This commit is contained in:
HTGAzureX1212. 2024-01-23 10:56:33 +08:00
parent 0011fac90d
commit f3682a1304
No known key found for this signature in database
GPG Key ID: 89A2F7143673C5B9
6 changed files with 26 additions and 7 deletions

View File

@ -110,6 +110,14 @@ fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
}
}
impl IntoDiagnosticArg for Vec<char> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
DiagnosticArgValue::StrListSepByAnd(
self.into_iter().map(|c| Cow::Owned(format!("{c:?}"))).collect(),
)
}
}
impl IntoDiagnosticArg for Symbol {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
self.to_ident_string().into_diagnostic_arg()

View File

@ -240,7 +240,7 @@ lint_hidden_unicode_codepoints = unicode codepoint changing visible direction of
lint_identifier_non_ascii_char = identifier contains non-ASCII characters
lint_identifier_uncommon_codepoints = identifier contains uncommon Unicode codepoints
lint_identifier_uncommon_codepoints = identifier contains uncommon Unicode codepoints: {$codepoints}
lint_ignored_unless_crate_specified = {$level}({$name}) is ignored unless specified at crate level

View File

@ -1107,7 +1107,9 @@ pub struct MultipleSupertraitUpcastable {
#[derive(LintDiagnostic)]
#[diag(lint_identifier_uncommon_codepoints)]
pub struct IdentifierUncommonCodepoints;
pub struct IdentifierUncommonCodepoints {
pub codepoints: Vec<char>,
}
#[derive(LintDiagnostic)]
#[diag(lint_confusable_identifier_pair)]

View File

@ -190,7 +190,16 @@ fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
if check_uncommon_codepoints
&& !symbol_str.chars().all(GeneralSecurityProfile::identifier_allowed)
{
cx.emit_span_lint(UNCOMMON_CODEPOINTS, sp, IdentifierUncommonCodepoints);
cx.emit_span_lint(
UNCOMMON_CODEPOINTS,
sp,
IdentifierUncommonCodepoints {
codepoints: symbol_str
.chars()
.filter(|c| !GeneralSecurityProfile::identifier_allowed(*c))
.collect(),
},
);
}
}

View File

@ -40,7 +40,7 @@ error: identifiers cannot contain emoji: `folded🙏🏿`
LL | let folded🙏🏿 = "modifier sequence";
| ^^^^^^^^^^
warning: identifier contains uncommon Unicode codepoints
warning: identifier contains uncommon Unicode codepoints: '\u{fe0f}'
--> $DIR/lex-emoji-identifiers.rs:6:9
|
LL | let key1⃣ = "keycap sequence";

View File

@ -1,4 +1,4 @@
error: identifier contains uncommon Unicode codepoints
error: identifier contains uncommon Unicode codepoints: 'µ'
--> $DIR/lint-uncommon-codepoints.rs:3:7
|
LL | const µ: f64 = 0.000001;
@ -10,13 +10,13 @@ note: the lint level is defined here
LL | #![deny(uncommon_codepoints)]
| ^^^^^^^^^^^^^^^^^^^
error: identifier contains uncommon Unicode codepoints
error: identifier contains uncommon Unicode codepoints: 'ij'
--> $DIR/lint-uncommon-codepoints.rs:6:4
|
LL | fn dijkstra() {}
| ^^^^^^^
error: identifier contains uncommon Unicode codepoints
error: identifier contains uncommon Unicode codepoints: 'ㇻ', 'ㇲ', and 'ㇳ'
--> $DIR/lint-uncommon-codepoints.rs:9:9
|
LL | let ㇻㇲㇳ = "rust";