File tree 1 file changed +18
-23
lines changed 1 file changed +18
-23
lines changed Original file line number Diff line number Diff line change @@ -82,30 +82,25 @@ impl EarlyLintPass for DisallowedScriptIdents {
82
82
// Note: `symbol.as_str()` is an expensive operation, thus should not be called
83
83
// more than once for a single symbol.
84
84
let symbol_str = symbol. as_str ( ) ;
85
- if symbol_str. is_ascii ( ) {
86
- continue ;
87
- }
88
85
89
- for c in symbol_str. chars ( ) {
90
- // We want to iterate through all the scripts associated with this character
91
- // and check whether at least of one scripts is in the whitelist.
92
- let forbidden_script = c
93
- . script_extension ( )
94
- . iter ( )
95
- . find ( |script| !self . whitelist . contains ( script) ) ;
96
- if let Some ( script) = forbidden_script {
97
- span_lint (
98
- cx,
99
- DISALLOWED_SCRIPT_IDENTS ,
100
- span,
101
- format ! (
102
- "identifier `{symbol_str}` has a Unicode script that is not allowed by configuration: {}" ,
103
- script. full_name( )
104
- ) ,
105
- ) ;
106
- // We don't want to spawn warning multiple times over a single identifier.
107
- break ;
108
- }
86
+ // Check if any character in the symbol is not part of any allowed script.
87
+ // Fast path for ascii-only idents.
88
+ if !symbol_str. is_ascii ( )
89
+ && let Some ( script) = symbol_str. chars ( ) . find_map ( |c| {
90
+ c. script_extension ( )
91
+ . iter ( )
92
+ . find ( |script| !self . whitelist . contains ( script) )
93
+ } )
94
+ {
95
+ span_lint (
96
+ cx,
97
+ DISALLOWED_SCRIPT_IDENTS ,
98
+ span,
99
+ format ! (
100
+ "identifier `{symbol_str}` has a Unicode script that is not allowed by configuration: {}" ,
101
+ script. full_name( )
102
+ ) ,
103
+ ) ;
109
104
}
110
105
}
111
106
}
You can’t perform that action at this time.
0 commit comments