@@ -492,6 +492,20 @@ fn generate_item_def_id_path(
492492 Ok ( ( url_parts, shortty, fqp) )
493493}
494494
495+ /// Checks if the given defid refers to an item that is unnamable, such as one defined in a const block.
496+ fn is_unnamable ( tcx : TyCtxt < ' _ > , did : DefId ) -> bool {
497+ let mut cur_did = did;
498+ while let Some ( parent) = tcx. opt_parent ( cur_did) {
499+ match tcx. def_kind ( parent) {
500+ // items defined in these can be linked to
501+ DefKind :: Mod | DefKind :: Impl { .. } | DefKind :: ForeignMod => cur_did = parent,
502+ // everything else does not have docs generated for it
503+ _ => return true ,
504+ }
505+ }
506+ return false ;
507+ }
508+
495509fn to_module_fqp ( shortty : ItemType , fqp : & [ Symbol ] ) -> & [ Symbol ] {
496510 if shortty == ItemType :: Module { fqp } else { & fqp[ ..fqp. len ( ) - 1 ] }
497511}
@@ -512,11 +526,7 @@ fn url_parts(
512526 Ok ( builder)
513527 }
514528 ExternalLocation :: Local => {
515- if module_fqp. iter ( ) . any ( |sym| sym. as_str ( ) == "_" ) {
516- Err ( HrefError :: UnnamableItem )
517- } else {
518529 Ok ( href_relative_parts ( module_fqp, relative_to) )
519- }
520530 }
521531 ExternalLocation :: Unknown => Err ( HrefError :: DocumentationNotBuilt ) ,
522532 }
@@ -571,6 +581,9 @@ pub(crate) fn href_with_root_path(
571581 }
572582 _ => original_did,
573583 } ;
584+ if is_unnamable ( cx. tcx ( ) , did) {
585+ return Err ( HrefError :: UnnamableItem ) ;
586+ }
574587 let cache = cx. cache ( ) ;
575588 let relative_to = & cx. current ;
576589
0 commit comments