@@ -19,8 +19,10 @@ use rustc_middle::ty;
1919use rustc_middle:: ty:: DefIdTree ;
2020use rustc_middle:: ty:: TyCtxt ;
2121use rustc_span:: def_id:: CRATE_DEF_INDEX ;
22+ use rustc_span:: Symbol ;
2223use rustc_target:: spec:: abi:: Abi ;
2324
25+ use crate :: clean:: utils:: join_path_segments;
2426use crate :: clean:: { self , utils:: find_nearest_parent_module, ExternalCrate , ItemId , PrimitiveType } ;
2527use crate :: formats:: item_type:: ItemType ;
2628use crate :: html:: escape:: Escape ;
@@ -505,7 +507,7 @@ crate fn href_with_root_path(
505507 did : DefId ,
506508 cx : & Context < ' _ > ,
507509 root_path : Option < & str > ,
508- ) -> Result < ( String , ItemType , Vec < String > ) , HrefError > {
510+ ) -> Result < ( String , ItemType , Vec < Symbol > ) , HrefError > {
509511 let tcx = cx. tcx ( ) ;
510512 let def_kind = tcx. def_kind ( did) ;
511513 let did = match def_kind {
@@ -517,7 +519,7 @@ crate fn href_with_root_path(
517519 } ;
518520 let cache = cx. cache ( ) ;
519521 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 ] {
521523 if shortty == ItemType :: Module { fqp } else { & fqp[ ..fqp. len ( ) - 1 ] }
522524 }
523525
@@ -547,7 +549,7 @@ crate fn href_with_root_path(
547549 is_remote = true ;
548550 let s = s. trim_end_matches ( '/' ) ;
549551 let mut builder = UrlPartsBuilder :: singleton ( s) ;
550- builder. extend ( module_fqp. iter ( ) . map ( String :: as_str ) ) ;
552+ builder. extend ( module_fqp. iter ( ) . copied ( ) ) ;
551553 builder
552554 }
553555 ExternalLocation :: Local => href_relative_parts ( module_fqp, relative_to) ,
@@ -566,7 +568,7 @@ crate fn href_with_root_path(
566568 }
567569 }
568570 debug ! ( ?url_parts) ;
569- let last = & fqp. last ( ) . unwrap ( ) [ .. ] ;
571+ let last = & * fqp. last ( ) . unwrap ( ) . as_str ( ) ;
570572 match shortty {
571573 ItemType :: Module => {
572574 url_parts. push ( "index.html" ) ;
@@ -579,25 +581,28 @@ crate fn href_with_root_path(
579581 Ok ( ( url_parts. finish ( ) , shortty, fqp. to_vec ( ) ) )
580582}
581583
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 > {
583585 href_with_root_path ( did, cx, None )
584586}
585587
586588/// Both paths should only be modules.
587589/// This is because modules get their own directories; that is, `std::vec` and `std::vec::Vec` will
588590/// 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 {
590592 for ( i, ( f, r) ) in fqp. iter ( ) . zip ( relative_to_fqp. iter ( ) ) . enumerate ( ) {
591593 // 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 {
593595 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;
596601 }
597602 }
598603 // e.g. linking to std::sync::atomic from std::sync
599604 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 ( )
601606 // e.g. linking to std::sync from std::sync::atomic
602607 } else if fqp. len ( ) < relative_to_fqp. len ( ) {
603608 let dissimilar_part_count = relative_to_fqp. len ( ) - fqp. len ( ) ;
@@ -631,8 +636,8 @@ fn resolved_path<'cx>(
631636 if let Ok ( ( _, _, fqp) ) = href ( did, cx) {
632637 format ! (
633638 "{}::{}" ,
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)
636641 )
637642 } else {
638643 last. name . to_string ( )
@@ -743,7 +748,7 @@ crate fn anchor<'a, 'cx: 'a>(
743748 short_ty,
744749 url,
745750 short_ty,
746- fqp . join ( "::" ) ,
751+ join_path_segments ( & fqp ) ,
747752 text
748753 )
749754 } else {
@@ -961,7 +966,7 @@ fn fmt_type<'cx>(
961966 url = url,
962967 shortty = ItemType :: AssocType ,
963968 name = name,
964- path = path . join ( "::" )
969+ path = join_path_segments ( path ) ,
965970 ) ?;
966971 }
967972 _ => write ! ( f, "{}" , name) ?,
0 commit comments