@@ -484,7 +484,11 @@ crate enum HrefError {
484484 NotInExternalCache ,
485485}
486486
487- crate fn href ( did : DefId , cx : & Context < ' _ > ) -> Result < ( String , ItemType , Vec < String > ) , HrefError > {
487+ crate fn href_with_root_path (
488+ did : DefId ,
489+ cx : & Context < ' _ > ,
490+ root_path : Option < & str > ,
491+ ) -> Result < ( String , ItemType , Vec < String > ) , HrefError > {
488492 let cache = & cx. cache ( ) ;
489493 let relative_to = & cx. current ;
490494 fn to_module_fqp ( shortty : ItemType , fqp : & [ String ] ) -> & [ String ] {
@@ -495,6 +499,7 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Str
495499 return Err ( HrefError :: Private ) ;
496500 }
497501
502+ let mut is_remote = false ;
498503 let ( fqp, shortty, mut url_parts) = match cache. paths . get ( & did) {
499504 Some ( & ( ref fqp, shortty) ) => ( fqp, shortty, {
500505 let module_fqp = to_module_fqp ( shortty, fqp) ;
@@ -508,6 +513,7 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Str
508513 shortty,
509514 match cache. extern_locations [ & did. krate ] {
510515 ExternalLocation :: Remote ( ref s) => {
516+ is_remote = true ;
511517 let s = s. trim_end_matches ( '/' ) ;
512518 let mut s = vec ! [ s] ;
513519 s. extend ( module_fqp[ ..] . iter ( ) . map ( String :: as_str) ) ;
@@ -522,6 +528,12 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Str
522528 }
523529 }
524530 } ;
531+ if !is_remote {
532+ if let Some ( root_path) = root_path {
533+ let root = root_path. trim_end_matches ( '/' ) ;
534+ url_parts. insert ( 0 , root) ;
535+ }
536+ }
525537 let last = & fqp. last ( ) . unwrap ( ) [ ..] ;
526538 let filename;
527539 match shortty {
@@ -536,6 +548,10 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Str
536548 Ok ( ( url_parts. join ( "/" ) , shortty, fqp. to_vec ( ) ) )
537549}
538550
551+ crate fn href ( did : DefId , cx : & Context < ' _ > ) -> Result < ( String , ItemType , Vec < String > ) , HrefError > {
552+ href_with_root_path ( did, cx, None )
553+ }
554+
539555/// Both paths should only be modules.
540556/// This is because modules get their own directories; that is, `std::vec` and `std::vec::Vec` will
541557/// both need `../iter/trait.Iterator.html` to get at the iterator trait.
0 commit comments