@@ -560,64 +560,51 @@ fn string<T: Display>(
560560 context : Option < & Context < ' _ > > ,
561561 root_path : & str ,
562562) {
563- match klass {
564- None => write ! ( out, "{}" , text) ,
565- Some ( klass) => {
566- if let Some ( def_span) = klass. get_span ( ) {
567- let mut text = text. to_string ( ) ;
568- if text. contains ( "::" ) {
569- text =
570- text. split ( "::" ) . enumerate ( ) . fold ( String :: new ( ) , |mut path, ( pos, t) | {
571- let pre = if pos != 0 { "::" } else { "" } ;
572- match t {
573- "self" | "Self" => write ! (
574- & mut path,
575- "{}<span class=\" {}\" >{}</span>" ,
576- pre,
577- Class :: Self_ ( ( 0 , 0 ) ) . as_html( ) ,
578- t
579- ) ,
580- "crate" | "super" => write ! (
581- & mut path,
582- "{}<span class=\" {}\" >{}</span>" ,
583- pre,
584- Class :: KeyWord . as_html( ) ,
585- t
586- ) ,
587- t => write ! ( & mut path, "{}{}" , pre, t) ,
588- }
589- . expect ( "Failed to build source HTML path" ) ;
590- path
591- } ) ;
563+ let klass = match klass {
564+ None => return write ! ( out, "{}" , text) ,
565+ Some ( klass) => klass,
566+ } ;
567+ if let Some ( def_span) = klass. get_span ( ) {
568+ let mut text = text. to_string ( ) ;
569+ if text. contains ( "::" ) {
570+ text = text. split ( "::" ) . intersperse ( "::" ) . fold ( String :: new ( ) , |mut path, t| {
571+ match t {
572+ "self" | "Self" => write ! (
573+ & mut path,
574+ "<span class=\" {}\" >{}</span>" ,
575+ Class :: Self_ ( ( 0 , 0 ) ) . as_html( ) ,
576+ t
577+ ) ,
578+ "crate" | "super" => write ! (
579+ & mut path,
580+ "<span class=\" {}\" >{}</span>" ,
581+ Class :: KeyWord . as_html( ) ,
582+ t
583+ ) ,
584+ t => write ! ( & mut path, "{}" , t) ,
592585 }
593- if let Some ( context) = context {
594- if let Some ( href) =
595- context. shared . span_correspondance_map . get ( & def_span) . and_then ( |href| {
596- match href {
597- LinkFromSrc :: Local ( span) => {
598- eprintln ! ( "==> {:?}:{:?}" , span. lo( ) , span. hi( ) ) ;
599- context
600- . href_from_span ( clean:: Span :: wrap_raw ( * span) )
601- . map ( |s| format ! ( "{}{}" , root_path, s) )
602- }
603- LinkFromSrc :: External ( def_id) => {
604- format:: href ( * def_id, context) . map ( |( url, _, _) | url)
605- }
606- }
607- } )
608- {
609- write ! (
610- out,
611- "<a class=\" {}\" href=\" {}\" >{}</a>" ,
612- klass. as_html( ) ,
613- href,
614- text
615- ) ;
616- return ;
586+ . expect ( "Failed to build source HTML path" ) ;
587+ path
588+ } ) ;
589+ }
590+ if let Some ( context) = context {
591+ if let Some ( href) =
592+ context. shared . span_correspondance_map . get ( & def_span) . and_then ( |href| {
593+ match href {
594+ LinkFromSrc :: Local ( span) => {
595+ context
596+ . href_from_span ( clean:: Span :: wrap_raw ( * span) )
597+ . map ( |s| format ! ( "{}{}" , root_path, s) )
598+ }
599+ LinkFromSrc :: External ( def_id) => {
600+ format:: href ( * def_id, context) . map ( |( url, _, _) | url)
601+ }
617602 }
618- }
603+ } )
604+ {
605+ write ! ( out, "<a class=\" {}\" href=\" {}\" >{}</a>" , klass. as_html( ) , href, text) ;
606+ return ;
619607 }
620- write ! ( out, "<span class=\" {}\" >{}</span>" , klass. as_html( ) , text) ;
621608 }
622609 }
623610 write ! ( out, "<span class=\" {}\" >{}</span>" , klass. as_html( ) , text) ;
0 commit comments