Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Diagnostics for Uncommon Codepoints: Add List to Display Characters Involved #120259

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_errors/src/diagnostic_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
HTGAzureX1212 marked this conversation as resolved.
Show resolved Hide resolved

lint_ignored_unless_crate_specified = {$level}({$name}) is ignored unless specified at crate level

Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,9 @@ pub struct IdentifierNonAsciiChar;

#[derive(LintDiagnostic)]
#[diag(lint_identifier_uncommon_codepoints)]
pub struct IdentifierUncommonCodepoints;
pub struct IdentifierUncommonCodepoints {
pub codepoints: Vec<char>,
}
HTGAzureX1212 marked this conversation as resolved.
Show resolved Hide resolved

#[derive(LintDiagnostic)]
#[diag(lint_confusable_identifier_pair)]
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_lint/src/non_ascii_idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lexer/lex-emoji-identifiers.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";
Expand Down
Loading