@@ -481,6 +481,20 @@ fn generate_item_def_id_path(
481
481
Ok ( ( url_parts, shortty, fqp) )
482
482
}
483
483
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
490
+ DefKind :: Mod | DefKind :: Impl { .. } | DefKind :: ForeignMod => cur_did = parent,
491
+ // everything else does not have docs generated for it
492
+ _ => return true ,
493
+ }
494
+ }
495
+ return false ;
496
+ }
497
+
484
498
fn to_module_fqp ( shortty : ItemType , fqp : & [ Symbol ] ) -> & [ Symbol ] {
485
499
if shortty == ItemType :: Module { fqp } else { & fqp[ ..fqp. len ( ) - 1 ] }
486
500
}
@@ -500,13 +514,7 @@ fn url_parts(
500
514
builder. extend ( module_fqp. iter ( ) . copied ( ) ) ;
501
515
Ok ( builder)
502
516
}
503
- ExternalLocation :: Local => {
504
- if module_fqp. iter ( ) . any ( |sym| sym. as_str ( ) == "_" ) {
505
- Err ( HrefError :: UnnamableItem )
506
- } else {
507
- Ok ( href_relative_parts ( module_fqp, relative_to) )
508
- }
509
- }
517
+ ExternalLocation :: Local => Ok ( href_relative_parts ( module_fqp, relative_to) ) ,
510
518
ExternalLocation :: Unknown => Err ( HrefError :: DocumentationNotBuilt ) ,
511
519
}
512
520
}
@@ -560,6 +568,9 @@ pub(crate) fn href_with_root_path(
560
568
}
561
569
_ => original_did,
562
570
} ;
571
+ if is_unnamable ( cx. tcx ( ) , did) {
572
+ return Err ( HrefError :: UnnamableItem ) ;
573
+ }
563
574
let cache = cx. cache ( ) ;
564
575
let relative_to = & cx. current ;
565
576
0 commit comments