@@ -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 ;
@@ -647,33 +648,35 @@ pub(crate) fn href_relative_parts<'fqp>(
647648 }
648649}
649650
650- pub ( crate ) fn link_tooltip ( did : DefId , fragment : & Option < UrlFragment > , cx : & Context < ' _ > ) -> String {
651- let cache = cx. cache ( ) ;
652- let Some ( ( fqp, shortty) ) = cache. paths . get ( & did) . or_else ( || cache. external_paths . get ( & did) )
653- else {
654- return String :: new ( ) ;
655- } ;
656- let mut buf = String :: new ( ) ;
657- let fqp = if * shortty == ItemType :: Primitive {
658- // primitives are documented in a crate, but not actually part of it
659- & fqp[ fqp. len ( ) - 1 ..]
660- } else {
661- fqp
662- } ;
663- if let & Some ( UrlFragment :: Item ( id) ) = fragment {
664- write_str ( & mut buf, format_args ! ( "{} " , cx. tcx( ) . def_descr( id) ) ) ;
665- for component in fqp {
666- write_str ( & mut buf, format_args ! ( "{component}::" ) ) ;
667- }
668- write_str ( & mut buf, format_args ! ( "{}" , cx. tcx( ) . item_name( id) ) ) ;
669- } else if !fqp. is_empty ( ) {
670- let mut fqp_it = fqp. iter ( ) ;
671- write_str ( & mut buf, format_args ! ( "{shortty} {}" , fqp_it. next( ) . unwrap( ) ) ) ;
672- for component in fqp_it {
673- write_str ( & mut buf, format_args ! ( "::{component}" ) ) ;
651+ pub ( crate ) fn link_tooltip (
652+ did : DefId ,
653+ fragment : & Option < UrlFragment > ,
654+ cx : & Context < ' _ > ,
655+ ) -> impl fmt:: Display {
656+ fmt:: from_fn ( move |f| {
657+ let cache = cx. cache ( ) ;
658+ let Some ( ( fqp, shortty) ) = cache. paths . get ( & did) . or_else ( || cache. external_paths . get ( & did) )
659+ else {
660+ return Ok ( ( ) ) ;
661+ } ;
662+ let fqp = if * shortty == ItemType :: Primitive {
663+ // primitives are documented in a crate, but not actually part of it
664+ slice:: from_ref ( fqp. last ( ) . unwrap ( ) )
665+ } else {
666+ fqp
667+ } ;
668+ if let & Some ( UrlFragment :: Item ( id) ) = fragment {
669+ write ! ( f, "{} " , cx. tcx( ) . def_descr( id) ) ?;
670+ for component in fqp {
671+ write ! ( f, "{component}::" ) ?;
672+ }
673+ write ! ( f, "{}" , cx. tcx( ) . item_name( id) ) ?;
674+ } else if !fqp. is_empty ( ) {
675+ write ! ( f, "{shortty} " ) ?;
676+ fqp. iter ( ) . joined ( "::" , f) ?;
674677 }
675- }
676- buf
678+ Ok ( ( ) )
679+ } )
677680}
678681
679682/// Used to render a [`clean::Path`].
0 commit comments