@@ -492,6 +492,20 @@ fn generate_item_def_id_path(
492
492
Ok ( ( url_parts, shortty, fqp) )
493
493
}
494
494
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
+
495
509
fn to_module_fqp ( shortty : ItemType , fqp : & [ Symbol ] ) -> & [ Symbol ] {
496
510
if shortty == ItemType :: Module { fqp } else { & fqp[ ..fqp. len ( ) - 1 ] }
497
511
}
@@ -511,13 +525,7 @@ fn url_parts(
511
525
builder. extend ( module_fqp. iter ( ) . copied ( ) ) ;
512
526
Ok ( builder)
513
527
}
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) ) ,
521
529
ExternalLocation :: Unknown => Err ( HrefError :: DocumentationNotBuilt ) ,
522
530
}
523
531
}
@@ -571,6 +579,9 @@ pub(crate) fn href_with_root_path(
571
579
}
572
580
_ => original_did,
573
581
} ;
582
+ if is_unnamable ( cx. tcx ( ) , did) {
583
+ return Err ( HrefError :: UnnamableItem ) ;
584
+ }
574
585
let cache = cx. cache ( ) ;
575
586
let relative_to = & cx. current ;
576
587
0 commit comments