@@ -472,15 +472,26 @@ impl clean::GenericArgs {
472472 }
473473}
474474
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 > {
476487 let cache = & cx. cache ( ) ;
477488 let relative_to = & cx. current ;
478489 fn to_module_fqp ( shortty : ItemType , fqp : & [ String ] ) -> & [ String ] {
479490 if shortty == ItemType :: Module { & fqp[ ..] } else { & fqp[ ..fqp. len ( ) - 1 ] }
480491 }
481492
482493 if !did. is_local ( ) && !cache. access_levels . is_public ( did) && !cache. document_private {
483- return None ;
494+ return Err ( HrefError :: Unavailable ) ;
484495 }
485496
486497 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
489500 href_relative_parts ( module_fqp, relative_to)
490501 } ) ,
491502 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+ }
508522 }
509523 } ;
510524 let last = & fqp. last ( ) . unwrap ( ) [ ..] ;
@@ -518,7 +532,7 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Option<(String, ItemType, Vec<Str
518532 url_parts. push ( & filename) ;
519533 }
520534 }
521- Some ( ( url_parts. join ( "/" ) , shortty, fqp. to_vec ( ) ) )
535+ Ok ( ( url_parts. join ( "/" ) , shortty, fqp. to_vec ( ) ) )
522536}
523537
524538/// Both paths should only be modules.
@@ -567,7 +581,7 @@ fn resolved_path<'a, 'cx: 'a>(
567581 write ! ( w, "{}{:#}" , & last. name, last. args. print( cx) ) ?;
568582 } else {
569583 let path = if use_absolute {
570- if let Some ( ( _, _, fqp) ) = href ( did, cx) {
584+ if let Ok ( ( _, _, fqp) ) = href ( did, cx) {
571585 format ! (
572586 "{}::{}" ,
573587 fqp[ ..fqp. len( ) - 1 ] . join( "::" ) ,
@@ -675,7 +689,7 @@ crate fn anchor<'a, 'cx: 'a>(
675689) -> impl fmt:: Display + ' a {
676690 let parts = href ( did. into ( ) , cx) ;
677691 display_fn ( move |f| {
678- if let Some ( ( url, short_ty, fqp) ) = parts {
692+ if let Ok ( ( url, short_ty, fqp) ) = parts {
679693 write ! (
680694 f,
681695 r#"<a class="{}" href="{}" title="{} {}">{}</a>"# ,
@@ -907,7 +921,7 @@ fn fmt_type<'cx>(
907921 // look at).
908922 box clean:: ResolvedPath { did, .. } => {
909923 match href ( did. into ( ) , cx) {
910- Some ( ( ref url, _, ref path) ) if !f. alternate ( ) => {
924+ Ok ( ( ref url, _, ref path) ) if !f. alternate ( ) => {
911925 write ! (
912926 f,
913927 "<a class=\" type\" href=\" {url}#{shortty}.{name}\" \
0 commit comments