@@ -484,7 +484,11 @@ crate enum HrefError {
484
484
NotInExternalCache ,
485
485
}
486
486
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 > {
488
492
let cache = & cx. cache ( ) ;
489
493
let relative_to = & cx. current ;
490
494
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
495
499
return Err ( HrefError :: Private ) ;
496
500
}
497
501
502
+ let mut is_remote = false ;
498
503
let ( fqp, shortty, mut url_parts) = match cache. paths . get ( & did) {
499
504
Some ( & ( ref fqp, shortty) ) => ( fqp, shortty, {
500
505
let module_fqp = to_module_fqp ( shortty, fqp) ;
@@ -508,6 +513,7 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Str
508
513
shortty,
509
514
match cache. extern_locations [ & did. krate ] {
510
515
ExternalLocation :: Remote ( ref s) => {
516
+ is_remote = true ;
511
517
let s = s. trim_end_matches ( '/' ) ;
512
518
let mut s = vec ! [ s] ;
513
519
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
522
528
}
523
529
}
524
530
} ;
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
+ }
525
537
let last = & fqp. last ( ) . unwrap ( ) [ ..] ;
526
538
let filename;
527
539
match shortty {
@@ -536,6 +548,10 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Str
536
548
Ok ( ( url_parts. join ( "/" ) , shortty, fqp. to_vec ( ) ) )
537
549
}
538
550
551
+ crate fn href ( did : DefId , cx : & Context < ' _ > ) -> Result < ( String , ItemType , Vec < String > ) , HrefError > {
552
+ href_with_root_path ( did, cx, None )
553
+ }
554
+
539
555
/// Both paths should only be modules.
540
556
/// This is because modules get their own directories; that is, `std::vec` and `std::vec::Vec` will
541
557
/// both need `../iter/trait.Iterator.html` to get at the iterator trait.
0 commit comments