Skip to content

Commit 3a07333

Browse files
committed
address requested changes
1 parent f3682a1 commit 3a07333

File tree

7 files changed

+18
-13
lines changed

7 files changed

+18
-13
lines changed

compiler/rustc_lint/messages.ftl

+4-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ lint_hidden_unicode_codepoints = unicode codepoint changing visible direction of
240240
241241
lint_identifier_non_ascii_char = identifier contains non-ASCII characters
242242
243-
lint_identifier_uncommon_codepoints = identifier contains uncommon Unicode codepoints: {$codepoints}
243+
lint_identifier_uncommon_codepoints = identifier contains {$codepoints_len ->
244+
[one] an uncommon Unicode codepoint
245+
*[other] uncommon Unicode codepoints
246+
}: {$codepoints}
244247
245248
lint_ignored_unless_crate_specified = {$level}({$name}) is ignored unless specified at crate level
246249

compiler/rustc_lint/src/lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,7 @@ pub struct IdentifierNonAsciiChar;
11091109
#[diag(lint_identifier_uncommon_codepoints)]
11101110
pub struct IdentifierUncommonCodepoints {
11111111
pub codepoints: Vec<char>,
1112+
pub codepoints_len: usize,
11121113
}
11131114

11141115
#[derive(LintDiagnostic)]

compiler/rustc_lint/src/non_ascii_idents.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,16 @@ impl EarlyLintPass for NonAsciiIdents {
190190
if check_uncommon_codepoints
191191
&& !symbol_str.chars().all(GeneralSecurityProfile::identifier_allowed)
192192
{
193+
let codepoints: Vec<_> = symbol_str
194+
.chars()
195+
.filter(|c| !GeneralSecurityProfile::identifier_allowed(*c))
196+
.collect();
197+
let codepoints_len = codepoints.len();
198+
193199
cx.emit_span_lint(
194200
UNCOMMON_CODEPOINTS,
195201
sp,
196-
IdentifierUncommonCodepoints {
197-
codepoints: symbol_str
198-
.chars()
199-
.filter(|c| !GeneralSecurityProfile::identifier_allowed(*c))
200-
.collect(),
201-
},
202+
IdentifierUncommonCodepoints { codepoints, codepoints_len },
202203
);
203204
}
204205
}

tests/ui/lexer/lex-emoji-identifiers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn invalid_emoji_usages() {
44
let wireless🛜 = "basic emoji"; //~ ERROR: identifiers cannot contain emoji
55
// FIXME
66
let key1️⃣ = "keycap sequence"; //~ ERROR: unknown start of token
7-
//~^ WARN: identifier contains uncommon Unicode codepoints
7+
//~^ WARN: identifier contains an uncommon Unicode codepoint
88
let flag🇺🇳 = "flag sequence"; //~ ERROR: identifiers cannot contain emoji
99
let wales🏴 = "tag sequence"; //~ ERROR: identifiers cannot contain emoji
1010
let folded🙏🏿 = "modifier sequence"; //~ ERROR: identifiers cannot contain emoji

tests/ui/lexer/lex-emoji-identifiers.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ error: identifiers cannot contain emoji: `folded🙏🏿`
4040
LL | let folded🙏🏿 = "modifier sequence";
4141
| ^^^^^^^^^^
4242

43-
warning: identifier contains uncommon Unicode codepoints: '\u{fe0f}'
43+
warning: identifier contains an uncommon Unicode codepoint: '\u{fe0f}'
4444
--> $DIR/lex-emoji-identifiers.rs:6:9
4545
|
4646
LL | let key1️⃣ = "keycap sequence";

tests/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![deny(uncommon_codepoints)]
22

3-
const µ: f64 = 0.000001; //~ ERROR identifier contains uncommon Unicode codepoints
3+
const µ: f64 = 0.000001; //~ ERROR identifier contains an uncommon Unicode codepoint
44
//~| WARNING should have an upper case name
55

6-
fn dijkstra() {} //~ ERROR identifier contains uncommon Unicode codepoints
6+
fn dijkstra() {} //~ ERROR identifier contains an uncommon Unicode codepoint
77

88
fn main() {
99
let ㇻㇲㇳ = "rust"; //~ ERROR identifier contains uncommon Unicode codepoints

tests/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: identifier contains uncommon Unicode codepoints: 'µ'
1+
error: identifier contains an uncommon Unicode codepoint: 'µ'
22
--> $DIR/lint-uncommon-codepoints.rs:3:7
33
|
44
LL | const µ: f64 = 0.000001;
@@ -10,7 +10,7 @@ note: the lint level is defined here
1010
LL | #![deny(uncommon_codepoints)]
1111
| ^^^^^^^^^^^^^^^^^^^
1212

13-
error: identifier contains uncommon Unicode codepoints: 'ij'
13+
error: identifier contains an uncommon Unicode codepoint: 'ij'
1414
--> $DIR/lint-uncommon-codepoints.rs:6:4
1515
|
1616
LL | fn dijkstra() {}

0 commit comments

Comments
 (0)