File tree 7 files changed +84
-4
lines changed
lint/rfc-2457-non-ascii-idents
7 files changed +84
-4
lines changed Original file line number Diff line number Diff line change @@ -3642,6 +3642,7 @@ dependencies = [
3642
3642
" rustc_span" ,
3643
3643
" rustc_target" ,
3644
3644
" syntax" ,
3645
+ " unicode-security" ,
3645
3646
]
3646
3647
3647
3648
[[package ]]
@@ -4940,6 +4941,21 @@ dependencies = [
4940
4941
" smallvec 1.0.0" ,
4941
4942
]
4942
4943
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
+
4943
4959
[[package ]]
4944
4960
name = " unicode-segmentation"
4945
4961
version = " 1.6.0"
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ path = "lib.rs"
10
10
11
11
[dependencies ]
12
12
log = " 0.4"
13
+ unicode-security = " 0.0.2"
13
14
rustc = { path = " ../librustc" }
14
15
rustc_target = { path = " ../librustc_target" }
15
16
syntax = { path = " ../libsyntax" }
Original file line number Diff line number Diff line change @@ -7,15 +7,32 @@ declare_lint! {
7
7
"detects non-ASCII identifiers"
8
8
}
9
9
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 ] ) ;
11
17
12
18
impl EarlyLintPass for NonAsciiIdents {
13
19
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) {
15
32
cx. struct_span_lint (
16
- NON_ASCII_IDENTS ,
33
+ UNCOMMON_CODEPOINTS ,
17
34
ident. span ,
18
- "identifier contains non-ASCII characters " ,
35
+ "identifier contains uncommon Unicode codepoints " ,
19
36
)
20
37
. emit ( ) ;
21
38
}
Original file line number Diff line number Diff line change 11
11
// ignore-asmjs wasm2js does not support source maps yet
12
12
13
13
#![ feature( non_ascii_idents) ]
14
+ #[ allow( uncommon_codepoints) ]
14
15
15
16
#[ path = "issue-48508-aux.rs" ]
16
17
mod other_file;
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<'_>] = &[
171
171
Crate ( "thread_local" ) ,
172
172
Crate ( "ucd-util" ) ,
173
173
Crate ( "unicode-normalization" ) ,
174
+ Crate ( "unicode-script" ) ,
175
+ Crate ( "unicode-security" ) ,
174
176
Crate ( "unicode-width" ) ,
175
177
Crate ( "unicode-xid" ) ,
176
178
Crate ( "unreachable" ) ,
You can’t perform that action at this time.
0 commit comments