mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
add list of characters to uncommon codepoints lint
This commit is contained in:
parent
0011fac90d
commit
f3682a1304
@ -110,6 +110,14 @@ impl IntoDiagnosticArg for char {
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -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
|
||||
|
||||
|
@ -1107,7 +1107,9 @@ pub struct IdentifierNonAsciiChar;
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_identifier_uncommon_codepoints)]
|
||||
pub struct IdentifierUncommonCodepoints;
|
||||
pub struct IdentifierUncommonCodepoints {
|
||||
pub codepoints: Vec<char>,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_confusable_identifier_pair)]
|
||||
|
@ -190,7 +190,16 @@ impl EarlyLintPass for NonAsciiIdents {
|
||||
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(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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";
|
||||
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user