@@ -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
}
@@ -512,11 +526,7 @@ fn url_parts(
512
526
Ok ( builder)
513
527
}
514
528
ExternalLocation :: Local => {
515
- if module_fqp. iter ( ) . any ( |sym| sym. as_str ( ) == "_" ) {
516
- Err ( HrefError :: UnnamableItem )
517
- } else {
518
529
Ok ( href_relative_parts ( module_fqp, relative_to) )
519
- }
520
530
}
521
531
ExternalLocation :: Unknown => Err ( HrefError :: DocumentationNotBuilt ) ,
522
532
}
@@ -571,6 +581,9 @@ pub(crate) fn href_with_root_path(
571
581
}
572
582
_ => original_did,
573
583
} ;
584
+ if is_unnamable ( cx. tcx ( ) , did) {
585
+ return Err ( HrefError :: UnnamableItem ) ;
586
+ }
574
587
let cache = cx. cache ( ) ;
575
588
let relative_to = & cx. current ;
576
589
0 commit comments