@@ -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}
@@ -511,13 +525,7 @@ fn url_parts(
511525 builder. extend ( module_fqp. iter ( ) . copied ( ) ) ;
512526 Ok ( builder)
513527 }
514- ExternalLocation :: Local => {
515- if module_fqp. iter ( ) . any ( |sym| sym. as_str ( ) == "_" ) {
516- Err ( HrefError :: UnnamableItem )
517- } else {
518- Ok ( href_relative_parts ( module_fqp, relative_to) )
519- }
520- }
528+ ExternalLocation :: Local => Ok ( href_relative_parts ( module_fqp, relative_to) ) ,
521529 ExternalLocation :: Unknown => Err ( HrefError :: DocumentationNotBuilt ) ,
522530 }
523531}
@@ -571,6 +579,9 @@ pub(crate) fn href_with_root_path(
571579 }
572580 _ => original_did,
573581 } ;
582+ if is_unnamable ( cx. tcx ( ) , did) {
583+ return Err ( HrefError :: UnnamableItem ) ;
584+ }
574585 let cache = cx. cache ( ) ;
575586 let relative_to = & cx. current ;
576587
0 commit comments