File tree Expand file tree Collapse file tree 6 files changed +83
-4
lines changed
test/ui/lint/rfc-2457-non-ascii-idents Expand file tree Collapse file tree 6 files changed +83
-4
lines changed Original file line number Diff line number Diff line change @@ -3642,6 +3642,7 @@ dependencies = [
36423642 " rustc_span" ,
36433643 " rustc_target" ,
36443644 " syntax" ,
3645+ " unicode-security" ,
36453646]
36463647
36473648[[package ]]
@@ -4940,6 +4941,21 @@ dependencies = [
49404941 " smallvec 1.0.0" ,
49414942]
49424943
4944+ [[package ]]
4945+ name = " unicode-script"
4946+ version = " 0.4.0"
4947+ source = " registry+https://github.com/rust-lang/crates.io-index"
4948+ checksum = " 5b2c5c29e805da6817f5af6a627d65adb045cebf05cccd5a3493d6109454391c"
4949+
4950+ [[package ]]
4951+ name = " unicode-security"
4952+ version = " 0.0.2"
4953+ source = " registry+https://github.com/rust-lang/crates.io-index"
4954+ checksum = " c49d35967fa037b881acc34ef717c38c4b5560eba10e3685271b3f530bb19634"
4955+ dependencies = [
4956+ " unicode-script" ,
4957+ ]
4958+
49434959[[package ]]
49444960name = " unicode-segmentation"
49454961version = " 1.6.0"
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ path = "lib.rs"
1010
1111[dependencies ]
1212log = " 0.4"
13+ unicode-security = " 0.0.2"
1314rustc = { path = " ../librustc" }
1415rustc_target = { path = " ../librustc_target" }
1516syntax = { path = " ../libsyntax" }
Original file line number Diff line number Diff line change @@ -7,15 +7,32 @@ declare_lint! {
77 "detects non-ASCII identifiers"
88}
99
10- declare_lint_pass ! ( NonAsciiIdents => [ NON_ASCII_IDENTS ] ) ;
10+ declare_lint ! {
11+ pub UNCOMMON_CODEPOINTS ,
12+ Warn ,
13+ "detects uncommon Unicode codepoints in identifiers"
14+ }
15+
16+ declare_lint_pass ! ( NonAsciiIdents => [ NON_ASCII_IDENTS , UNCOMMON_CODEPOINTS ] ) ;
1117
1218impl EarlyLintPass for NonAsciiIdents {
1319 fn check_ident ( & mut self , cx : & EarlyContext < ' _ > , ident : ast:: Ident ) {
14- if !ident. name . as_str ( ) . is_ascii ( ) {
20+ use unicode_security:: GeneralSecurityProfile ;
21+ let name_str = ident. name . as_str ( ) ;
22+ if name_str. is_ascii ( ) {
23+ return ;
24+ }
25+ cx. struct_span_lint (
26+ NON_ASCII_IDENTS ,
27+ ident. span ,
28+ "identifier contains non-ASCII characters" ,
29+ )
30+ . emit ( ) ;
31+ if !name_str. chars ( ) . all ( GeneralSecurityProfile :: identifier_allowed) {
1532 cx. struct_span_lint (
16- NON_ASCII_IDENTS ,
33+ UNCOMMON_CODEPOINTS ,
1734 ident. span ,
18- "identifier contains non-ASCII characters " ,
35+ "identifier contains uncommon Unicode codepoints " ,
1936 )
2037 . emit ( ) ;
2138 }
Original file line number Diff line number Diff line change 1+ #![ feature( non_ascii_idents) ]
2+ #![ deny( uncommon_codepoints) ]
3+
4+ const µ: f64 = 0.000001 ; //~ ERROR identifier contains uncommon Unicode codepoints
5+
6+ fn dijkstra ( ) { } //~ ERROR identifier contains uncommon Unicode codepoints
7+
8+ fn main ( ) {
9+ let ㇻㇲㇳ = "rust" ; //~ ERROR identifier contains uncommon Unicode codepoints
10+ println ! ( "{}" , ㇻㇲㇳ) ; //~ ERROR identifier contains uncommon Unicode codepoints
11+ }
Original file line number Diff line number Diff line change 1+ error: identifier contains uncommon Unicode codepoints
2+ --> $DIR/lint-uncommon-codepoints.rs:4:7
3+ |
4+ LL | const µ: f64 = 0.000001;
5+ | ^
6+ |
7+ note: lint level defined here
8+ --> $DIR/lint-uncommon-codepoints.rs:2:9
9+ |
10+ LL | #![deny(uncommon_codepoints)]
11+ | ^^^^^^^^^^^^^^^^^^^
12+
13+ error: identifier contains uncommon Unicode codepoints
14+ --> $DIR/lint-uncommon-codepoints.rs:6:4
15+ |
16+ LL | fn dijkstra() {}
17+ | ^^^^^^^
18+
19+ error: identifier contains uncommon Unicode codepoints
20+ --> $DIR/lint-uncommon-codepoints.rs:9:9
21+ |
22+ LL | let ㇻㇲㇳ = "rust";
23+ | ^^^^^^
24+
25+ error: identifier contains uncommon Unicode codepoints
26+ --> $DIR/lint-uncommon-codepoints.rs:10:20
27+ |
28+ LL | println!("{}", ㇻㇲㇳ);
29+ | ^^^^^^
30+
31+ error: aborting due to 4 previous errors
32+
Original file line number Diff line number Diff line change @@ -171,6 +171,8 @@ const WHITELIST: &[Crate<'_>] = &[
171171 Crate ( "thread_local" ) ,
172172 Crate ( "ucd-util" ) ,
173173 Crate ( "unicode-normalization" ) ,
174+ Crate ( "unicode-script" ) ,
175+ Crate ( "unicode-security" ) ,
174176 Crate ( "unicode-width" ) ,
175177 Crate ( "unicode-xid" ) ,
176178 Crate ( "unreachable" ) ,
You can’t perform that action at this time.
0 commit comments