@@ -235,6 +235,12 @@ impl<'a> Classifier<'a> {
235
235
}
236
236
}
237
237
238
+ /// Convenient wrapper around [`LightSpan::new_in_file`] to prevent passing the `file_span_lo`
239
+ /// argument every time.
240
+ fn new_light_span ( & self , lo : u32 , hi : u32 ) -> LightSpan {
241
+ LightSpan :: new_in_file ( self . file_span_lo , lo, hi)
242
+ }
243
+
238
244
/// Concatenate colons and idents as one when possible.
239
245
fn get_full_ident_path ( & mut self ) -> Vec < ( TokenKind , usize , usize ) > {
240
246
let start = self . byte_pos as usize ;
@@ -313,14 +319,12 @@ impl<'a> Classifier<'a> {
313
319
. unwrap_or ( false )
314
320
{
315
321
let tokens = self . get_full_ident_path ( ) ;
316
- // We need this variable because `tokens` is consumed in the loop.
317
- let skip = !tokens. is_empty ( ) ;
318
- for ( token, start, end) in tokens {
319
- let text = & self . src [ start..end] ;
320
- self . advance ( token, text, sink, start as u32 ) ;
322
+ for ( token, start, end) in & tokens {
323
+ let text = & self . src [ * start..* end] ;
324
+ self . advance ( * token, text, sink, * start as u32 ) ;
321
325
self . byte_pos += text. len ( ) as u32 ;
322
326
}
323
- if skip {
327
+ if !tokens . is_empty ( ) {
324
328
continue ;
325
329
}
326
330
}
@@ -483,24 +487,16 @@ impl<'a> Classifier<'a> {
483
487
self . in_macro_nonterminal = false ;
484
488
Class :: MacroNonTerminal
485
489
}
486
- "self" | "Self" => Class :: Self_ ( LightSpan :: new_in_file (
487
- self . file_span_lo ,
488
- before,
489
- before + text. len ( ) as u32 ,
490
- ) ) ,
491
- _ => Class :: Ident ( LightSpan :: new_in_file (
492
- self . file_span_lo ,
493
- before,
494
- before + text. len ( ) as u32 ,
495
- ) ) ,
490
+ "self" | "Self" => {
491
+ Class :: Self_ ( self . new_light_span ( before, before + text. len ( ) as u32 ) )
492
+ }
493
+ _ => Class :: Ident ( self . new_light_span ( before, before + text. len ( ) as u32 ) ) ,
496
494
} ,
497
495
Some ( c) => c,
498
496
} ,
499
- TokenKind :: RawIdent | TokenKind :: UnknownPrefix => Class :: Ident ( LightSpan :: new_in_file (
500
- self . file_span_lo ,
501
- before,
502
- before + text. len ( ) as u32 ,
503
- ) ) ,
497
+ TokenKind :: RawIdent | TokenKind :: UnknownPrefix => {
498
+ Class :: Ident ( self . new_light_span ( before, before + text. len ( ) as u32 ) )
499
+ }
504
500
TokenKind :: Lifetime { .. } => Class :: Lifetime ,
505
501
} ;
506
502
// Anything that didn't return above is the simple case where we the
@@ -564,7 +560,7 @@ fn string<T: Display>(
564
560
"self" | "Self" => write ! (
565
561
& mut path,
566
562
"<span class=\" {}\" >{}</span>" ,
567
- Class :: Self_ ( LightSpan :: empty ( ) ) . as_html( ) ,
563
+ Class :: Self_ ( LightSpan :: dummy ( ) ) . as_html( ) ,
568
564
t
569
565
) ,
570
566
"crate" | "super" => {
0 commit comments