@@ -11,6 +11,7 @@ use std::borrow::Cow;
1111use std:: cmp:: Ordering ;
1212use std:: fmt:: { self , Display , Write } ;
1313use std:: iter:: { self , once} ;
14+ use std:: slice;
1415
1516use itertools:: Either ;
1617use rustc_abi:: ExternAbi ;
@@ -650,33 +651,35 @@ pub(crate) fn href_relative_parts<'fqp>(
650651 }
651652}
652653
653- pub ( crate ) fn link_tooltip ( did : DefId , fragment : & Option < UrlFragment > , cx : & Context < ' _ > ) -> String {
654- let cache = cx. cache ( ) ;
655- let Some ( ( fqp, shortty) ) = cache. paths . get ( & did) . or_else ( || cache. external_paths . get ( & did) )
656- else {
657- return String :: new ( ) ;
658- } ;
659- let mut buf = String :: new ( ) ;
660- let fqp = if * shortty == ItemType :: Primitive {
661- // primitives are documented in a crate, but not actually part of it
662- & fqp[ fqp. len ( ) - 1 ..]
663- } else {
664- fqp
665- } ;
666- if let & Some ( UrlFragment :: Item ( id) ) = fragment {
667- write_str ( & mut buf, format_args ! ( "{} " , cx. tcx( ) . def_descr( id) ) ) ;
668- for component in fqp {
669- write_str ( & mut buf, format_args ! ( "{component}::" ) ) ;
670- }
671- write_str ( & mut buf, format_args ! ( "{}" , cx. tcx( ) . item_name( id) ) ) ;
672- } else if !fqp. is_empty ( ) {
673- let mut fqp_it = fqp. iter ( ) ;
674- write_str ( & mut buf, format_args ! ( "{shortty} {}" , fqp_it. next( ) . unwrap( ) ) ) ;
675- for component in fqp_it {
676- write_str ( & mut buf, format_args ! ( "::{component}" ) ) ;
654+ pub ( crate ) fn link_tooltip (
655+ did : DefId ,
656+ fragment : & Option < UrlFragment > ,
657+ cx : & Context < ' _ > ,
658+ ) -> impl fmt:: Display {
659+ fmt:: from_fn ( move |f| {
660+ let cache = cx. cache ( ) ;
661+ let Some ( ( fqp, shortty) ) = cache. paths . get ( & did) . or_else ( || cache. external_paths . get ( & did) )
662+ else {
663+ return Ok ( ( ) ) ;
664+ } ;
665+ let fqp = if * shortty == ItemType :: Primitive {
666+ // primitives are documented in a crate, but not actually part of it
667+ slice:: from_ref ( fqp. last ( ) . unwrap ( ) )
668+ } else {
669+ fqp
670+ } ;
671+ if let & Some ( UrlFragment :: Item ( id) ) = fragment {
672+ write ! ( f, "{} " , cx. tcx( ) . def_descr( id) ) ?;
673+ for component in fqp {
674+ write ! ( f, "{component}::" ) ?;
675+ }
676+ write ! ( f, "{}" , cx. tcx( ) . item_name( id) ) ?;
677+ } else if !fqp. is_empty ( ) {
678+ write ! ( f, "{shortty} " ) ?;
679+ fqp. iter ( ) . joined ( "::" , f) ?;
677680 }
678- }
679- buf
681+ Ok ( ( ) )
682+ } )
680683}
681684
682685/// Used to render a [`clean::Path`].
0 commit comments