@@ -313,6 +313,7 @@ impl<'a> Classifier<'a> {
313
313
. unwrap_or ( false )
314
314
{
315
315
let tokens = self . get_full_ident_path ( ) ;
316
+ // We need this variable because `tokens` is consumed in the loop.
316
317
let skip = !tokens. is_empty ( ) ;
317
318
for ( token, start, end) in tokens {
318
319
let text = & self . src [ start..end] ;
@@ -549,51 +550,51 @@ fn string<T: Display>(
549
550
None => return write ! ( out, "{}" , text) ,
550
551
Some ( klass) => klass,
551
552
} ;
552
- if let Some ( def_span) = klass. get_span ( ) {
553
- let mut text = text. to_string ( ) ;
554
- if text. contains ( "::" ) {
555
- text = text. split ( "::" ) . intersperse ( "::" ) . fold ( String :: new ( ) , |mut path, t| {
556
- match t {
557
- "self" | "Self" => write ! (
558
- & mut path,
559
- "<span class=\" {}\" >{}</span>" ,
560
- Class :: Self_ ( LightSpan :: empty( ) ) . as_html( ) ,
561
- t
562
- ) ,
563
- "crate" | "super" => write ! (
564
- & mut path,
565
- "<span class=\" {}\" >{}</span>" ,
566
- Class :: KeyWord . as_html( ) ,
567
- t
568
- ) ,
569
- t => write ! ( & mut path, "{}" , t) ,
570
- }
571
- . expect ( "Failed to build source HTML path" ) ;
572
- path
573
- } ) ;
553
+ let def_span = match klass. get_span ( ) {
554
+ Some ( d) => d,
555
+ None => {
556
+ write ! ( out, "<span class=\" {}\" >{}</span>" , klass. as_html( ) , text) ;
557
+ return ;
574
558
}
575
- if let Some ( context_info) = context_info {
576
- if let Some ( href) =
577
- context_info. context . shared . span_correspondance_map . get ( & def_span) . and_then (
578
- |href| {
579
- let context = context_info. context ;
580
- match href {
581
- LinkFromSrc :: Local ( span) => context
582
- . href_from_span ( * span)
583
- . map ( |s| format ! ( "{}{}" , context_info. root_path, s) ) ,
584
- LinkFromSrc :: External ( def_id) => {
585
- format:: href ( * def_id, context) . map ( |( url, _, _) | url)
586
- }
587
- }
588
- } ,
589
- )
590
- {
591
- write ! ( out, "<a class=\" {}\" href=\" {}\" >{}</a>" , klass. as_html( ) , href, text) ;
592
- return ;
559
+ } ;
560
+ let mut text_s = text. to_string ( ) ;
561
+ if text_s. contains ( "::" ) {
562
+ text_s = text_s. split ( "::" ) . intersperse ( "::" ) . fold ( String :: new ( ) , |mut path, t| {
563
+ match t {
564
+ "self" | "Self" => write ! (
565
+ & mut path,
566
+ "<span class=\" {}\" >{}</span>" ,
567
+ Class :: Self_ ( LightSpan :: empty( ) ) . as_html( ) ,
568
+ t
569
+ ) ,
570
+ "crate" | "super" => {
571
+ write ! ( & mut path, "<span class=\" {}\" >{}</span>" , Class :: KeyWord . as_html( ) , t)
572
+ }
573
+ t => write ! ( & mut path, "{}" , t) ,
593
574
}
575
+ . expect ( "Failed to build source HTML path" ) ;
576
+ path
577
+ } ) ;
578
+ }
579
+ if let Some ( context_info) = context_info {
580
+ if let Some ( href) =
581
+ context_info. context . shared . span_correspondance_map . get ( & def_span) . and_then ( |href| {
582
+ let context = context_info. context ;
583
+ match href {
584
+ LinkFromSrc :: Local ( span) => context
585
+ . href_from_span ( * span)
586
+ . map ( |s| format ! ( "{}{}" , context_info. root_path, s) ) ,
587
+ LinkFromSrc :: External ( def_id) => {
588
+ format:: href ( * def_id, context) . map ( |( url, _, _) | url)
589
+ }
590
+ }
591
+ } )
592
+ {
593
+ write ! ( out, "<a class=\" {}\" href=\" {}\" >{}</a>" , klass. as_html( ) , href, text_s) ;
594
+ return ;
594
595
}
595
596
}
596
- write ! ( out, "<span class=\" {}\" >{}</span>" , klass. as_html( ) , text ) ;
597
+ write ! ( out, "<span class=\" {}\" >{}</span>" , klass. as_html( ) , text_s ) ;
597
598
}
598
599
599
600
#[ cfg( test) ]
0 commit comments