@@ -190,90 +190,33 @@ impl EarlyLintPass for NonAsciiIdents {
190190 if check_uncommon_codepoints
191191 && !symbol_str. chars ( ) . all ( GeneralSecurityProfile :: identifier_allowed)
192192 {
193- let mut chars = symbol_str. chars ( ) . collect :: < Vec < _ > > ( ) ;
194-
195- let exclusion = chars
196- . extract_if ( |c| {
197- GeneralSecurityProfile :: identifier_type ( * c)
198- == Some ( IdentifierType :: Exclusion )
199- } )
200- . collect :: < Vec < _ > > ( ) ;
201- if !exclusion. is_empty ( ) {
202- let exclusion_len = exclusion. len ( ) ;
203-
204- cx. emit_span_lint (
205- UNCOMMON_CODEPOINTS ,
206- sp,
207- IdentifierUncommonCodepoints {
208- codepoints : exclusion,
209- codepoints_len : exclusion_len,
210- identifier_type : String :: from ( "Exclusion" ) ,
211- } ,
212- ) ;
213- }
214-
215- let technical = chars
216- . extract_if ( |c| {
217- GeneralSecurityProfile :: identifier_type ( * c)
218- == Some ( IdentifierType :: Technical )
219- } )
220- . collect :: < Vec < _ > > ( ) ;
221- if !technical. is_empty ( ) {
222- let technical_len = technical. len ( ) ;
223-
224- cx. emit_span_lint (
225- UNCOMMON_CODEPOINTS ,
226- sp,
227- IdentifierUncommonCodepoints {
228- codepoints : technical,
229- codepoints_len : technical_len,
230- identifier_type : String :: from ( "Technical" ) ,
231- } ,
232- ) ;
233- }
234-
235- let limited_use = chars
236- . extract_if ( |c| {
237- GeneralSecurityProfile :: identifier_type ( * c)
238- == Some ( IdentifierType :: Limited_Use )
239- } )
240- . collect :: < Vec < _ > > ( ) ;
241- if !limited_use. is_empty ( ) {
242- let limited_use_len = limited_use. len ( ) ;
243-
244- cx. emit_span_lint (
245- UNCOMMON_CODEPOINTS ,
246- sp,
247- IdentifierUncommonCodepoints {
248- codepoints : limited_use,
249- codepoints_len : limited_use_len,
250- identifier_type : String :: from ( "Limited_Use" ) ,
251- } ,
252- ) ;
253- }
254-
255- let not_nfkc = chars
256- . extract_if ( |c| {
257- GeneralSecurityProfile :: identifier_type ( * c)
258- == Some ( IdentifierType :: Not_NFKC )
259- } )
260- . collect :: < Vec < _ > > ( ) ;
261- if !not_nfkc. is_empty ( ) {
262- let not_nfkc_len = not_nfkc. len ( ) ;
263-
193+ let mut chars: Vec < _ > = symbol_str. chars ( )
194+ . map ( |c| ( c, GeneralSecurityProfile :: identifier_type ( c) ) )
195+ . collect ( ) ;
196+
197+ for ( id_ty, id_ty_descr) in [
198+ ( IdentifierType :: Exclusion , "Exclusion" ) ,
199+ ( IdentifierType :: Technical , "Technical" ) ,
200+ ( IdentifierType :: Limited_Use , "Limited_Use" ) ,
201+ ( IdentifierType :: Not_NFKC , "Not_NFKC" ) ,
202+ ] {
203+ let codepoints: Vec < _ > = chars. extract_if ( |( _, ty) | * ty == Some ( id_ty) ) . collect ( ) ;
204+ if codepoints. is_empty ( ) {
205+ continue ;
206+ }
264207 cx. emit_span_lint (
265208 UNCOMMON_CODEPOINTS ,
266209 sp,
267210 IdentifierUncommonCodepoints {
268- codepoints : not_nfkc ,
269- codepoints_len : not_nfkc_len ,
270- identifier_type : String :: from ( "Not_NFKC" ) ,
211+ codepoints_len : codepoints . len ( ) ,
212+ codepoints : codepoints . into_iter ( ) . map ( | ( c , _ ) | c ) . collect ( ) ,
213+ identifier_type : id_ty_descr ,
271214 } ,
272215 ) ;
273216 }
274217
275218 let remaining = chars
276- . extract_if ( |c | !GeneralSecurityProfile :: identifier_allowed ( * c) )
219+ . extract_if ( |( c , _ ) | !GeneralSecurityProfile :: identifier_allowed ( * c) )
277220 . collect :: < Vec < _ > > ( ) ;
278221 if !remaining. is_empty ( ) {
279222 let remaining_len = remaining. len ( ) ;
@@ -282,9 +225,9 @@ impl EarlyLintPass for NonAsciiIdents {
282225 UNCOMMON_CODEPOINTS ,
283226 sp,
284227 IdentifierUncommonCodepoints {
285- codepoints : remaining,
228+ codepoints : remaining. iter ( ) . map ( | ( c , _ ) | * c ) . collect ( ) ,
286229 codepoints_len : remaining_len,
287- identifier_type : String :: new ( ) ,
230+ identifier_type : "Restricted" ,
288231 } ,
289232 ) ;
290233 }
0 commit comments