@@ -19,8 +19,10 @@ use rustc_middle::ty;
19
19
use rustc_middle:: ty:: DefIdTree ;
20
20
use rustc_middle:: ty:: TyCtxt ;
21
21
use rustc_span:: def_id:: CRATE_DEF_INDEX ;
22
+ use rustc_span:: Symbol ;
22
23
use rustc_target:: spec:: abi:: Abi ;
23
24
25
+ use crate :: clean:: utils:: join_path_segments;
24
26
use crate :: clean:: { self , utils:: find_nearest_parent_module, ExternalCrate , ItemId , PrimitiveType } ;
25
27
use crate :: formats:: item_type:: ItemType ;
26
28
use crate :: html:: escape:: Escape ;
@@ -505,7 +507,7 @@ crate fn href_with_root_path(
505
507
did : DefId ,
506
508
cx : & Context < ' _ > ,
507
509
root_path : Option < & str > ,
508
- ) -> Result < ( String , ItemType , Vec < String > ) , HrefError > {
510
+ ) -> Result < ( String , ItemType , Vec < Symbol > ) , HrefError > {
509
511
let tcx = cx. tcx ( ) ;
510
512
let def_kind = tcx. def_kind ( did) ;
511
513
let did = match def_kind {
@@ -517,7 +519,7 @@ crate fn href_with_root_path(
517
519
} ;
518
520
let cache = cx. cache ( ) ;
519
521
let relative_to = & cx. current ;
520
- fn to_module_fqp ( shortty : ItemType , fqp : & [ String ] ) -> & [ String ] {
522
+ fn to_module_fqp ( shortty : ItemType , fqp : & [ Symbol ] ) -> & [ Symbol ] {
521
523
if shortty == ItemType :: Module { fqp } else { & fqp[ ..fqp. len ( ) - 1 ] }
522
524
}
523
525
@@ -547,7 +549,7 @@ crate fn href_with_root_path(
547
549
is_remote = true ;
548
550
let s = s. trim_end_matches ( '/' ) ;
549
551
let mut builder = UrlPartsBuilder :: singleton ( s) ;
550
- builder. extend ( module_fqp. iter ( ) . map ( String :: as_str ) ) ;
552
+ builder. extend ( module_fqp. iter ( ) . copied ( ) ) ;
551
553
builder
552
554
}
553
555
ExternalLocation :: Local => href_relative_parts ( module_fqp, relative_to) ,
@@ -566,7 +568,7 @@ crate fn href_with_root_path(
566
568
}
567
569
}
568
570
debug ! ( ?url_parts) ;
569
- let last = & fqp. last ( ) . unwrap ( ) [ .. ] ;
571
+ let last = & * fqp. last ( ) . unwrap ( ) . as_str ( ) ;
570
572
match shortty {
571
573
ItemType :: Module => {
572
574
url_parts. push ( "index.html" ) ;
@@ -579,25 +581,28 @@ crate fn href_with_root_path(
579
581
Ok ( ( url_parts. finish ( ) , shortty, fqp. to_vec ( ) ) )
580
582
}
581
583
582
- crate fn href ( did : DefId , cx : & Context < ' _ > ) -> Result < ( String , ItemType , Vec < String > ) , HrefError > {
584
+ crate fn href ( did : DefId , cx : & Context < ' _ > ) -> Result < ( String , ItemType , Vec < Symbol > ) , HrefError > {
583
585
href_with_root_path ( did, cx, None )
584
586
}
585
587
586
588
/// Both paths should only be modules.
587
589
/// This is because modules get their own directories; that is, `std::vec` and `std::vec::Vec` will
588
590
/// both need `../iter/trait.Iterator.html` to get at the iterator trait.
589
- crate fn href_relative_parts ( fqp : & [ String ] , relative_to_fqp : & [ String ] ) -> UrlPartsBuilder {
591
+ crate fn href_relative_parts ( fqp : & [ Symbol ] , relative_to_fqp : & [ String ] ) -> UrlPartsBuilder {
590
592
for ( i, ( f, r) ) in fqp. iter ( ) . zip ( relative_to_fqp. iter ( ) ) . enumerate ( ) {
591
593
// e.g. linking to std::iter from std::vec (`dissimilar_part_count` will be 1)
592
- if f != r {
594
+ if & * f . as_str ( ) != r {
593
595
let dissimilar_part_count = relative_to_fqp. len ( ) - i;
594
- let fqp_module = fqp[ i..fqp. len ( ) ] . iter ( ) . map ( String :: as_str) ;
595
- return iter:: repeat ( ".." ) . take ( dissimilar_part_count) . chain ( fqp_module) . collect ( ) ;
596
+ let fqp_module = & fqp[ i..fqp. len ( ) ] ;
597
+ let mut builder: UrlPartsBuilder =
598
+ iter:: repeat ( ".." ) . take ( dissimilar_part_count) . collect ( ) ;
599
+ builder. extend ( fqp_module. iter ( ) . copied ( ) ) ;
600
+ return builder;
596
601
}
597
602
}
598
603
// e.g. linking to std::sync::atomic from std::sync
599
604
if relative_to_fqp. len ( ) < fqp. len ( ) {
600
- fqp[ relative_to_fqp. len ( ) ..fqp. len ( ) ] . iter ( ) . map ( String :: as_str ) . collect ( )
605
+ fqp[ relative_to_fqp. len ( ) ..fqp. len ( ) ] . iter ( ) . copied ( ) . collect ( )
601
606
// e.g. linking to std::sync from std::sync::atomic
602
607
} else if fqp. len ( ) < relative_to_fqp. len ( ) {
603
608
let dissimilar_part_count = relative_to_fqp. len ( ) - fqp. len ( ) ;
@@ -631,8 +636,8 @@ fn resolved_path<'cx>(
631
636
if let Ok ( ( _, _, fqp) ) = href ( did, cx) {
632
637
format ! (
633
638
"{}::{}" ,
634
- fqp[ ..fqp. len( ) - 1 ] . join ( "::" ) ,
635
- anchor( did, fqp. last( ) . unwrap( ) , cx)
639
+ join_path_segments ( & fqp[ ..fqp. len( ) - 1 ] ) ,
640
+ anchor( did, & fqp. last( ) . unwrap( ) . as_str ( ) , cx)
636
641
)
637
642
} else {
638
643
last. name . to_string ( )
@@ -743,7 +748,7 @@ crate fn anchor<'a, 'cx: 'a>(
743
748
short_ty,
744
749
url,
745
750
short_ty,
746
- fqp . join ( "::" ) ,
751
+ join_path_segments ( & fqp ) ,
747
752
text
748
753
)
749
754
} else {
@@ -961,7 +966,7 @@ fn fmt_type<'cx>(
961
966
url = url,
962
967
shortty = ItemType :: AssocType ,
963
968
name = name,
964
- path = path . join ( "::" )
969
+ path = join_path_segments ( path ) ,
965
970
) ?;
966
971
}
967
972
_ => write ! ( f, "{}" , name) ?,
0 commit comments