@@ -483,12 +483,12 @@ fn generate_item_def_id_path(
483483 let mut is_remote = false ;
484484
485485 let url_parts = url_parts ( cx. cache ( ) , def_id, module_fqp, & cx. current , & mut is_remote) ?;
486- let ( url_parts, shortty , fqp ) = make_href ( root_path, shortty, url_parts, & fqp, is_remote) ? ;
487- if def_id = = original_def_id {
488- return Ok ( ( url_parts , shortty , fqp ) ) ;
489- }
490- let kind = ItemType :: from_def_kind ( original_def_kind , Some ( def_kind ) ) ;
491- Ok ( ( format ! ( "{ url_parts}#{kind}.{}" , tcx . item_name ( original_def_id ) ) , shortty, fqp) )
486+ let mut url_parts = make_href ( root_path, shortty, url_parts, & fqp, is_remote) ;
487+ if def_id ! = original_def_id {
488+ let kind = ItemType :: from_def_kind ( original_def_kind , Some ( def_kind ) ) ;
489+ url_parts = format ! ( "{url_parts}#{kind}.{}" , tcx . item_name ( original_def_id ) )
490+ } ;
491+ Ok ( ( url_parts, shortty, fqp) )
492492}
493493
494494fn to_module_fqp ( shortty : ItemType , fqp : & [ Symbol ] ) -> & [ Symbol ] {
@@ -510,7 +510,7 @@ fn url_parts(
510510 builder. extend ( module_fqp. iter ( ) . copied ( ) ) ;
511511 Ok ( builder)
512512 }
513- ExternalLocation :: Local => Ok ( href_relative_parts ( module_fqp, relative_to) . collect ( ) ) ,
513+ ExternalLocation :: Local => Ok ( href_relative_parts ( module_fqp, relative_to) ) ,
514514 ExternalLocation :: Unknown => Err ( HrefError :: DocumentationNotBuilt ) ,
515515 }
516516}
@@ -521,7 +521,7 @@ fn make_href(
521521 mut url_parts : UrlPartsBuilder ,
522522 fqp : & [ Symbol ] ,
523523 is_remote : bool ,
524- ) -> Result < ( String , ItemType , Vec < Symbol > ) , HrefError > {
524+ ) -> String {
525525 if !is_remote && let Some ( root_path) = root_path {
526526 let root = root_path. trim_end_matches ( '/' ) ;
527527 url_parts. push_front ( root) ;
@@ -536,7 +536,7 @@ fn make_href(
536536 url_parts. push_fmt ( format_args ! ( "{shortty}.{last}.html" ) ) ;
537537 }
538538 }
539- Ok ( ( url_parts. finish ( ) , shortty , fqp . to_vec ( ) ) )
539+ url_parts. finish ( )
540540}
541541
542542pub ( crate ) fn href_with_root_path (
@@ -587,7 +587,7 @@ pub(crate) fn href_with_root_path(
587587 Some ( & ( ref fqp, shortty) ) => ( fqp, shortty, {
588588 let module_fqp = to_module_fqp ( shortty, fqp. as_slice ( ) ) ;
589589 debug ! ( ?fqp, ?shortty, ?module_fqp) ;
590- href_relative_parts ( module_fqp, relative_to) . collect ( )
590+ href_relative_parts ( module_fqp, relative_to)
591591 } ) ,
592592 None => {
593593 // Associated items are handled differently with "jump to def". The anchor is generated
@@ -606,7 +606,8 @@ pub(crate) fn href_with_root_path(
606606 }
607607 }
608608 } ;
609- make_href ( root_path, shortty, url_parts, fqp, is_remote)
609+ let url_parts = make_href ( root_path, shortty, url_parts, & fqp, is_remote) ;
610+ Ok ( ( url_parts, shortty, fqp. clone ( ) ) )
610611}
611612
612613pub ( crate ) fn href (
@@ -619,34 +620,30 @@ pub(crate) fn href(
619620/// Both paths should only be modules.
620621/// This is because modules get their own directories; that is, `std::vec` and `std::vec::Vec` will
621622/// both need `../iter/trait.Iterator.html` to get at the iterator trait.
622- pub ( crate ) fn href_relative_parts < ' fqp > (
623- fqp : & ' fqp [ Symbol ] ,
624- relative_to_fqp : & [ Symbol ] ,
625- ) -> Box < dyn Iterator < Item = Symbol > + ' fqp > {
623+ pub ( crate ) fn href_relative_parts ( fqp : & [ Symbol ] , relative_to_fqp : & [ Symbol ] ) -> UrlPartsBuilder {
626624 for ( i, ( f, r) ) in fqp. iter ( ) . zip ( relative_to_fqp. iter ( ) ) . enumerate ( ) {
627625 // e.g. linking to std::iter from std::vec (`dissimilar_part_count` will be 1)
628626 if f != r {
629627 let dissimilar_part_count = relative_to_fqp. len ( ) - i;
630628 let fqp_module = & fqp[ i..] ;
631- return Box :: new (
632- iter:: repeat_n ( sym:: dotdot, dissimilar_part_count)
633- . chain ( fqp_module. iter ( ) . copied ( ) ) ,
634- ) ;
629+ return iter:: repeat_n ( sym:: dotdot, dissimilar_part_count)
630+ . chain ( fqp_module. iter ( ) . copied ( ) )
631+ . collect ( ) ;
635632 }
636633 }
637634 match relative_to_fqp. len ( ) . cmp ( & fqp. len ( ) ) {
638635 Ordering :: Less => {
639636 // e.g. linking to std::sync::atomic from std::sync
640- Box :: new ( fqp[ relative_to_fqp. len ( ) ..fqp. len ( ) ] . iter ( ) . copied ( ) )
637+ fqp[ relative_to_fqp. len ( ) ..fqp. len ( ) ] . iter ( ) . copied ( ) . collect ( )
641638 }
642639 Ordering :: Greater => {
643640 // e.g. linking to std::sync from std::sync::atomic
644641 let dissimilar_part_count = relative_to_fqp. len ( ) - fqp. len ( ) ;
645- Box :: new ( iter:: repeat_n ( sym:: dotdot, dissimilar_part_count) )
642+ iter:: repeat_n ( sym:: dotdot, dissimilar_part_count) . collect ( )
646643 }
647644 Ordering :: Equal => {
648645 // linking to the same module
649- Box :: new ( iter :: empty ( ) )
646+ UrlPartsBuilder :: new ( )
650647 }
651648 }
652649}
@@ -708,13 +705,13 @@ fn resolved_path(
708705 f,
709706 "{path}::{anchor}" ,
710707 path = join_with_double_colon( & fqp[ ..fqp. len( ) - 1 ] ) ,
711- anchor = anchor ( did, * fqp. last( ) . unwrap( ) , cx)
708+ anchor = print_anchor ( did, * fqp. last( ) . unwrap( ) , cx)
712709 )
713710 } else {
714711 write ! ( f, "{}" , last. name)
715712 }
716713 } else {
717- write ! ( f, "{}" , anchor ( did, last. name, cx) )
714+ write ! ( f, "{}" , print_anchor ( did, last. name, cx) )
718715 }
719716 } ) ;
720717 write ! ( w, "{path}{args}" , args = last. args. print( cx) ) ?;
@@ -800,7 +797,7 @@ fn primitive_link_fragment(
800797 Ok ( ( ) )
801798}
802799
803- fn tybounds (
800+ fn print_tybounds (
804801 bounds : & [ clean:: PolyTrait ] ,
805802 lt : & Option < clean:: Lifetime > ,
806803 cx : & Context < ' _ > ,
@@ -832,7 +829,7 @@ fn print_higher_ranked_params_with_space(
832829 } )
833830}
834831
835- pub ( crate ) fn anchor ( did : DefId , text : Symbol , cx : & Context < ' _ > ) -> impl Display {
832+ pub ( crate ) fn print_anchor ( did : DefId , text : Symbol , cx : & Context < ' _ > ) -> impl Display {
836833 fmt:: from_fn ( move |f| {
837834 let parts = href ( did, cx) ;
838835 if let Ok ( ( url, short_ty, fqp) ) = parts {
@@ -866,7 +863,7 @@ fn fmt_type(
866863 }
867864 clean:: DynTrait ( bounds, lt) => {
868865 f. write_str ( "dyn " ) ?;
869- tybounds ( bounds, lt, cx) . fmt ( f)
866+ print_tybounds ( bounds, lt, cx) . fmt ( f)
870867 }
871868 clean:: Infer => write ! ( f, "_" ) ,
872869 clean:: Primitive ( clean:: PrimitiveType :: Never ) => {
@@ -1122,16 +1119,16 @@ impl clean::Impl {
11221119 write ! ( f, "!" ) ?;
11231120 }
11241121 if self . kind . is_fake_variadic ( )
1125- && let generics = ty. generics ( )
1126- && let & [ inner_type] = generics. as_ref ( ) . map_or ( & [ ] [ .. ] , |v| & v [ .. ] )
1122+ && let Some ( mut generics) = ty. generics ( )
1123+ && let ( Some ( inner_type) , None ) = ( generics. next ( ) , generics . next ( ) )
11271124 {
11281125 let last = ty. last ( ) ;
11291126 if f. alternate ( ) {
11301127 write ! ( f, "{}<" , last) ?;
11311128 self . print_type ( inner_type, f, use_absolute, cx) ?;
11321129 write ! ( f, ">" ) ?;
11331130 } else {
1134- write ! ( f, "{}<" , anchor ( ty. def_id( ) , last, cx) ) ?;
1131+ write ! ( f, "{}<" , print_anchor ( ty. def_id( ) , last, cx) ) ?;
11351132 self . print_type ( inner_type, f, use_absolute, cx) ?;
11361133 write ! ( f, ">" ) ?;
11371134 }
@@ -1201,12 +1198,11 @@ impl clean::Impl {
12011198 fmt_type ( & bare_fn. decl . output , f, use_absolute, cx) ?;
12021199 }
12031200 } else if let clean:: Type :: Path { path } = type_
1204- && let Some ( generics) = path. generics ( )
1205- && generics . len ( ) == 1
1201+ && let Some ( mut generics) = path. generics ( )
1202+ && let ( Some ( ty ) , None ) = ( generics . next ( ) , generics . next ( ) )
12061203 && self . kind . is_fake_variadic ( )
12071204 {
1208- let ty = generics[ 0 ] ;
1209- let wrapper = anchor ( path. def_id ( ) , path. last ( ) , cx) ;
1205+ let wrapper = print_anchor ( path. def_id ( ) , path. last ( ) , cx) ;
12101206 if f. alternate ( ) {
12111207 write ! ( f, "{wrapper:#}<" ) ?;
12121208 } else {
@@ -1419,7 +1415,7 @@ pub(crate) fn visibility_print_with_space(item: &clean::Item, cx: &Context<'_>)
14191415 debug ! ( "path={path:?}" ) ;
14201416 // modified from `resolved_path()` to work with `DefPathData`
14211417 let last_name = path. data . last ( ) . unwrap ( ) . data . get_opt_name ( ) . unwrap ( ) ;
1422- let anchor = anchor ( vis_did, last_name, cx) ;
1418+ let anchor = print_anchor ( vis_did, last_name, cx) ;
14231419
14241420 let mut s = "pub(in " . to_owned ( ) ;
14251421 for seg in & path. data [ ..path. data . len ( ) - 1 ] {
0 commit comments