@@ -235,6 +235,12 @@ impl<'a> Classifier<'a> {
235235 }
236236 }
237237
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+
238244 /// Concatenate colons and idents as one when possible.
239245 fn get_full_ident_path ( & mut self ) -> Vec < ( TokenKind , usize , usize ) > {
240246 let start = self . byte_pos as usize ;
@@ -313,14 +319,12 @@ impl<'a> Classifier<'a> {
313319 . unwrap_or ( false )
314320 {
315321 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 ) ;
321325 self . byte_pos += text. len ( ) as u32 ;
322326 }
323- if skip {
327+ if !tokens . is_empty ( ) {
324328 continue ;
325329 }
326330 }
@@ -483,24 +487,16 @@ impl<'a> Classifier<'a> {
483487 self . in_macro_nonterminal = false ;
484488 Class :: MacroNonTerminal
485489 }
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 ) ) ,
496494 } ,
497495 Some ( c) => c,
498496 } ,
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+ }
504500 TokenKind :: Lifetime { .. } => Class :: Lifetime ,
505501 } ;
506502 // Anything that didn't return above is the simple case where we the
@@ -564,7 +560,7 @@ fn string<T: Display>(
564560 "self" | "Self" => write ! (
565561 & mut path,
566562 "<span class=\" {}\" >{}</span>" ,
567- Class :: Self_ ( LightSpan :: empty ( ) ) . as_html( ) ,
563+ Class :: Self_ ( LightSpan :: dummy ( ) ) . as_html( ) ,
568564 t
569565 ) ,
570566 "crate" | "super" => {
0 commit comments