@@ -472,15 +472,26 @@ impl clean::GenericArgs {
472
472
}
473
473
}
474
474
475
- crate fn href ( did : DefId , cx : & Context < ' _ > ) -> Option < ( String , ItemType , Vec < String > ) > {
475
+ // Possible errors when computing href link source for a `DefId`
476
+ crate enum HrefError {
477
+ // `DefId` is in an unknown location. This seems to happen when building without dependencies
478
+ // but a trait from a dependency is still visible
479
+ UnknownLocation ,
480
+ // Unavailable because private
481
+ Unavailable ,
482
+ // Not in external cache, href link should be in same page
483
+ NotInExternalCache ,
484
+ }
485
+
486
+ crate fn href ( did : DefId , cx : & Context < ' _ > ) -> Result < ( String , ItemType , Vec < String > ) , HrefError > {
476
487
let cache = & cx. cache ( ) ;
477
488
let relative_to = & cx. current ;
478
489
fn to_module_fqp ( shortty : ItemType , fqp : & [ String ] ) -> & [ String ] {
479
490
if shortty == ItemType :: Module { & fqp[ ..] } else { & fqp[ ..fqp. len ( ) - 1 ] }
480
491
}
481
492
482
493
if !did. is_local ( ) && !cache. access_levels . is_public ( did) && !cache. document_private {
483
- return None ;
494
+ return Err ( HrefError :: Unavailable ) ;
484
495
}
485
496
486
497
let ( fqp, shortty, mut url_parts) = match cache. paths . get ( & did) {
@@ -489,22 +500,25 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Option<(String, ItemType, Vec<Str
489
500
href_relative_parts ( module_fqp, relative_to)
490
501
} ) ,
491
502
None => {
492
- let & ( ref fqp, shortty) = cache. external_paths . get ( & did) ?;
493
- let module_fqp = to_module_fqp ( shortty, fqp) ;
494
- (
495
- fqp,
496
- shortty,
497
- match cache. extern_locations [ & did. krate ] {
498
- ExternalLocation :: Remote ( ref s) => {
499
- let s = s. trim_end_matches ( '/' ) ;
500
- let mut s = vec ! [ & s[ ..] ] ;
501
- s. extend ( module_fqp[ ..] . iter ( ) . map ( String :: as_str) ) ;
502
- s
503
- }
504
- ExternalLocation :: Local => href_relative_parts ( module_fqp, relative_to) ,
505
- ExternalLocation :: Unknown => return None ,
506
- } ,
507
- )
503
+ if let Some ( & ( ref fqp, shortty) ) = cache. external_paths . get ( & did) {
504
+ let module_fqp = to_module_fqp ( shortty, fqp) ;
505
+ (
506
+ fqp,
507
+ shortty,
508
+ match cache. extern_locations [ & did. krate ] {
509
+ ExternalLocation :: Remote ( ref s) => {
510
+ let s = s. trim_end_matches ( '/' ) ;
511
+ let mut s = vec ! [ & s[ ..] ] ;
512
+ s. extend ( module_fqp[ ..] . iter ( ) . map ( String :: as_str) ) ;
513
+ s
514
+ }
515
+ ExternalLocation :: Local => href_relative_parts ( module_fqp, relative_to) ,
516
+ ExternalLocation :: Unknown => return Err ( HrefError :: UnknownLocation ) ,
517
+ } ,
518
+ )
519
+ } else {
520
+ return Err ( HrefError :: NotInExternalCache ) ;
521
+ }
508
522
}
509
523
} ;
510
524
let last = & fqp. last ( ) . unwrap ( ) [ ..] ;
@@ -518,7 +532,7 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Option<(String, ItemType, Vec<Str
518
532
url_parts. push ( & filename) ;
519
533
}
520
534
}
521
- Some ( ( url_parts. join ( "/" ) , shortty, fqp. to_vec ( ) ) )
535
+ Ok ( ( url_parts. join ( "/" ) , shortty, fqp. to_vec ( ) ) )
522
536
}
523
537
524
538
/// Both paths should only be modules.
@@ -567,7 +581,7 @@ fn resolved_path<'a, 'cx: 'a>(
567
581
write ! ( w, "{}{:#}" , & last. name, last. args. print( cx) ) ?;
568
582
} else {
569
583
let path = if use_absolute {
570
- if let Some ( ( _, _, fqp) ) = href ( did, cx) {
584
+ if let Ok ( ( _, _, fqp) ) = href ( did, cx) {
571
585
format ! (
572
586
"{}::{}" ,
573
587
fqp[ ..fqp. len( ) - 1 ] . join( "::" ) ,
@@ -675,7 +689,7 @@ crate fn anchor<'a, 'cx: 'a>(
675
689
) -> impl fmt:: Display + ' a {
676
690
let parts = href ( did. into ( ) , cx) ;
677
691
display_fn ( move |f| {
678
- if let Some ( ( url, short_ty, fqp) ) = parts {
692
+ if let Ok ( ( url, short_ty, fqp) ) = parts {
679
693
write ! (
680
694
f,
681
695
r#"<a class="{}" href="{}" title="{} {}">{}</a>"# ,
@@ -907,7 +921,7 @@ fn fmt_type<'cx>(
907
921
// look at).
908
922
box clean:: ResolvedPath { did, .. } => {
909
923
match href ( did. into ( ) , cx) {
910
- Some ( ( ref url, _, ref path) ) if !f. alternate ( ) => {
924
+ Ok ( ( ref url, _, ref path) ) if !f. alternate ( ) => {
911
925
write ! (
912
926
f,
913
927
"<a class=\" type\" href=\" {url}#{shortty}.{name}\" \
0 commit comments