@@ -368,6 +368,8 @@ pub(crate) enum HrefError {
368368Private , 
369369    // Not in external cache, href link should be in same page 
370370    NotInExternalCache , 
371+     /// Refers to an unnamable item, such as one defined within a function or const block. 
372+ UnnamableItem , 
371373} 
372374
373375/// This function is to get the external macro path because they are not in the cache used in 
@@ -479,6 +481,26 @@ fn generate_item_def_id_path(
479481    Ok ( ( url_parts,  shortty,  fqp) ) 
480482} 
481483
484+ /// Checks if the given defid refers to an item that is unnamable, such as one defined in a const block. 
485+ fn  is_unnamable ( tcx :  TyCtxt < ' _ > ,  did :  DefId )  -> bool  { 
486+     let  mut  cur_did = did; 
487+     while  let  Some ( parent)  = tcx. opt_parent ( cur_did)  { 
488+         match  tcx. def_kind ( parent)  { 
489+             // items defined in these can be linked to, as long as they are visible 
490+             DefKind :: Mod  | DefKind :: ForeignMod  => cur_did = parent, 
491+             // items in impls can be linked to, 
492+             // as long as we can link to the item the impl is on. 
493+             // since associated traits are not a thing, 
494+             // it should not be possible to refer to an impl item if 
495+             // the base type is not namable. 
496+             DefKind :: Impl  {  .. }  => return  false , 
497+             // everything else does not have docs generated for it 
498+             _ => return  true , 
499+         } 
500+     } 
501+     return  false ; 
502+ } 
503+ 
482504fn  to_module_fqp ( shortty :  ItemType ,  fqp :  & [ Symbol ] )  -> & [ Symbol ]  { 
483505    if  shortty == ItemType :: Module  {  fqp }  else  {  & fqp[ ..fqp. len ( )  - 1 ]  } 
484506} 
@@ -552,6 +574,9 @@ pub(crate) fn href_with_root_path(
552574        } 
553575        _ => original_did, 
554576    } ; 
577+     if  is_unnamable ( cx. tcx ( ) ,  did)  { 
578+         return  Err ( HrefError :: UnnamableItem ) ; 
579+     } 
555580    let  cache = cx. cache ( ) ; 
556581    let  relative_to = & cx. current ; 
557582
0 commit comments