@@ -7,6 +7,7 @@ use rustc_ast as ast;
7
7
use rustc_data_structures:: fx:: FxIndexMap ;
8
8
use rustc_data_structures:: unord:: UnordMap ;
9
9
use rustc_span:: symbol:: Symbol ;
10
+ use unicode_security:: general_security_profile:: IdentifierType ;
10
11
11
12
declare_lint ! {
12
13
/// The `non_ascii_idents` lint detects non-ASCII identifiers.
@@ -189,17 +190,47 @@ impl EarlyLintPass for NonAsciiIdents {
189
190
if check_uncommon_codepoints
190
191
&& !symbol_str. chars ( ) . all ( GeneralSecurityProfile :: identifier_allowed)
191
192
{
192
- let codepoints : Vec < _ > = symbol_str
193
+ let mut chars : Vec < _ > = symbol_str
193
194
. chars ( )
194
- . filter ( |c| ! GeneralSecurityProfile :: identifier_allowed ( * c ) )
195
+ . map ( |c| ( c , GeneralSecurityProfile :: identifier_type ( c ) ) )
195
196
. collect ( ) ;
196
- let codepoints_len = codepoints. len ( ) ;
197
197
198
- cx. emit_span_lint (
199
- UNCOMMON_CODEPOINTS ,
200
- sp,
201
- IdentifierUncommonCodepoints { codepoints, codepoints_len } ,
202
- ) ;
198
+ for ( id_ty, id_ty_descr) in [
199
+ ( IdentifierType :: Exclusion , "Exclusion" ) ,
200
+ ( IdentifierType :: Technical , "Technical" ) ,
201
+ ( IdentifierType :: Limited_Use , "Limited_Use" ) ,
202
+ ( IdentifierType :: Not_NFKC , "Not_NFKC" ) ,
203
+ ] {
204
+ let codepoints: Vec < _ > =
205
+ chars. extract_if ( |( _, ty) | * ty == Some ( id_ty) ) . collect ( ) ;
206
+ if codepoints. is_empty ( ) {
207
+ continue ;
208
+ }
209
+ cx. emit_span_lint (
210
+ UNCOMMON_CODEPOINTS ,
211
+ sp,
212
+ IdentifierUncommonCodepoints {
213
+ codepoints_len : codepoints. len ( ) ,
214
+ codepoints : codepoints. into_iter ( ) . map ( |( c, _) | c) . collect ( ) ,
215
+ identifier_type : id_ty_descr,
216
+ } ,
217
+ ) ;
218
+ }
219
+
220
+ let remaining = chars
221
+ . extract_if ( |( c, _) | !GeneralSecurityProfile :: identifier_allowed ( * c) )
222
+ . collect :: < Vec < _ > > ( ) ;
223
+ if !remaining. is_empty ( ) {
224
+ cx. emit_span_lint (
225
+ UNCOMMON_CODEPOINTS ,
226
+ sp,
227
+ IdentifierUncommonCodepoints {
228
+ codepoints_len : remaining. len ( ) ,
229
+ codepoints : remaining. into_iter ( ) . map ( |( c, _) | c) . collect ( ) ,
230
+ identifier_type : "Restricted" ,
231
+ } ,
232
+ ) ;
233
+ }
203
234
}
204
235
}
205
236
0 commit comments