@@ -483,12 +483,12 @@ fn generate_item_def_id_path(
483
483
let mut is_remote = false ;
484
484
485
485
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) )
492
492
}
493
493
494
494
fn to_module_fqp ( shortty : ItemType , fqp : & [ Symbol ] ) -> & [ Symbol ] {
@@ -510,7 +510,7 @@ fn url_parts(
510
510
builder. extend ( module_fqp. iter ( ) . copied ( ) ) ;
511
511
Ok ( builder)
512
512
}
513
- ExternalLocation :: Local => Ok ( href_relative_parts ( module_fqp, relative_to) . collect ( ) ) ,
513
+ ExternalLocation :: Local => Ok ( href_relative_parts ( module_fqp, relative_to) ) ,
514
514
ExternalLocation :: Unknown => Err ( HrefError :: DocumentationNotBuilt ) ,
515
515
}
516
516
}
@@ -521,7 +521,7 @@ fn make_href(
521
521
mut url_parts : UrlPartsBuilder ,
522
522
fqp : & [ Symbol ] ,
523
523
is_remote : bool ,
524
- ) -> Result < ( String , ItemType , Vec < Symbol > ) , HrefError > {
524
+ ) -> String {
525
525
if !is_remote && let Some ( root_path) = root_path {
526
526
let root = root_path. trim_end_matches ( '/' ) ;
527
527
url_parts. push_front ( root) ;
@@ -536,7 +536,7 @@ fn make_href(
536
536
url_parts. push_fmt ( format_args ! ( "{shortty}.{last}.html" ) ) ;
537
537
}
538
538
}
539
- Ok ( ( url_parts. finish ( ) , shortty , fqp . to_vec ( ) ) )
539
+ url_parts. finish ( )
540
540
}
541
541
542
542
pub ( crate ) fn href_with_root_path (
@@ -587,7 +587,7 @@ pub(crate) fn href_with_root_path(
587
587
Some ( & ( ref fqp, shortty) ) => ( fqp, shortty, {
588
588
let module_fqp = to_module_fqp ( shortty, fqp. as_slice ( ) ) ;
589
589
debug ! ( ?fqp, ?shortty, ?module_fqp) ;
590
- href_relative_parts ( module_fqp, relative_to) . collect ( )
590
+ href_relative_parts ( module_fqp, relative_to)
591
591
} ) ,
592
592
None => {
593
593
// Associated items are handled differently with "jump to def". The anchor is generated
@@ -606,7 +606,8 @@ pub(crate) fn href_with_root_path(
606
606
}
607
607
}
608
608
} ;
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 ( ) ) )
610
611
}
611
612
612
613
pub ( crate ) fn href (
@@ -619,34 +620,30 @@ pub(crate) fn href(
619
620
/// Both paths should only be modules.
620
621
/// This is because modules get their own directories; that is, `std::vec` and `std::vec::Vec` will
621
622
/// 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 {
626
624
for ( i, ( f, r) ) in fqp. iter ( ) . zip ( relative_to_fqp. iter ( ) ) . enumerate ( ) {
627
625
// e.g. linking to std::iter from std::vec (`dissimilar_part_count` will be 1)
628
626
if f != r {
629
627
let dissimilar_part_count = relative_to_fqp. len ( ) - i;
630
628
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 ( ) ;
635
632
}
636
633
}
637
634
match relative_to_fqp. len ( ) . cmp ( & fqp. len ( ) ) {
638
635
Ordering :: Less => {
639
636
// 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 ( )
641
638
}
642
639
Ordering :: Greater => {
643
640
// e.g. linking to std::sync from std::sync::atomic
644
641
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 ( )
646
643
}
647
644
Ordering :: Equal => {
648
645
// linking to the same module
649
- Box :: new ( iter :: empty ( ) )
646
+ UrlPartsBuilder :: new ( )
650
647
}
651
648
}
652
649
}
@@ -708,13 +705,13 @@ fn resolved_path(
708
705
f,
709
706
"{path}::{anchor}" ,
710
707
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)
712
709
)
713
710
} else {
714
711
write ! ( f, "{}" , last. name)
715
712
}
716
713
} else {
717
- write ! ( f, "{}" , anchor ( did, last. name, cx) )
714
+ write ! ( f, "{}" , print_anchor ( did, last. name, cx) )
718
715
}
719
716
} ) ;
720
717
write ! ( w, "{path}{args}" , args = last. args. print( cx) ) ?;
@@ -800,7 +797,7 @@ fn primitive_link_fragment(
800
797
Ok ( ( ) )
801
798
}
802
799
803
- fn tybounds (
800
+ fn print_tybounds (
804
801
bounds : & [ clean:: PolyTrait ] ,
805
802
lt : & Option < clean:: Lifetime > ,
806
803
cx : & Context < ' _ > ,
@@ -832,7 +829,7 @@ fn print_higher_ranked_params_with_space(
832
829
} )
833
830
}
834
831
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 {
836
833
fmt:: from_fn ( move |f| {
837
834
let parts = href ( did, cx) ;
838
835
if let Ok ( ( url, short_ty, fqp) ) = parts {
@@ -866,7 +863,7 @@ fn fmt_type(
866
863
}
867
864
clean:: DynTrait ( bounds, lt) => {
868
865
f. write_str ( "dyn " ) ?;
869
- tybounds ( bounds, lt, cx) . fmt ( f)
866
+ print_tybounds ( bounds, lt, cx) . fmt ( f)
870
867
}
871
868
clean:: Infer => write ! ( f, "_" ) ,
872
869
clean:: Primitive ( clean:: PrimitiveType :: Never ) => {
@@ -1122,16 +1119,16 @@ impl clean::Impl {
1122
1119
write ! ( f, "!" ) ?;
1123
1120
}
1124
1121
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 ( ) )
1127
1124
{
1128
1125
let last = ty. last ( ) ;
1129
1126
if f. alternate ( ) {
1130
1127
write ! ( f, "{}<" , last) ?;
1131
1128
self . print_type ( inner_type, f, use_absolute, cx) ?;
1132
1129
write ! ( f, ">" ) ?;
1133
1130
} else {
1134
- write ! ( f, "{}<" , anchor ( ty. def_id( ) , last, cx) ) ?;
1131
+ write ! ( f, "{}<" , print_anchor ( ty. def_id( ) , last, cx) ) ?;
1135
1132
self . print_type ( inner_type, f, use_absolute, cx) ?;
1136
1133
write ! ( f, ">" ) ?;
1137
1134
}
@@ -1201,12 +1198,11 @@ impl clean::Impl {
1201
1198
fmt_type ( & bare_fn. decl . output , f, use_absolute, cx) ?;
1202
1199
}
1203
1200
} 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 ( ) )
1206
1203
&& self . kind . is_fake_variadic ( )
1207
1204
{
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) ;
1210
1206
if f. alternate ( ) {
1211
1207
write ! ( f, "{wrapper:#}<" ) ?;
1212
1208
} else {
@@ -1419,7 +1415,7 @@ pub(crate) fn visibility_print_with_space(item: &clean::Item, cx: &Context<'_>)
1419
1415
debug ! ( "path={path:?}" ) ;
1420
1416
// modified from `resolved_path()` to work with `DefPathData`
1421
1417
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) ;
1423
1419
1424
1420
let mut s = "pub(in " . to_owned ( ) ;
1425
1421
for seg in & path. data [ ..path. data . len ( ) - 1 ] {
0 commit comments