@@ -50,7 +50,8 @@ enum ErrorKind {
50
50
51
51
struct LinkCollector < ' a , ' tcx > {
52
52
cx : & ' a DocContext < ' tcx > ,
53
- mod_ids : Vec < hir:: HirId > ,
53
+ // NOTE: this may not necessarily be a module in the current crate
54
+ mod_ids : Vec < DefId > ,
54
55
}
55
56
56
57
impl < ' a , ' tcx > LinkCollector < ' a , ' tcx > {
@@ -445,17 +446,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
445
446
fn fold_item ( & mut self , mut item : Item ) -> Option < Item > {
446
447
use rustc_middle:: ty:: DefIdTree ;
447
448
448
- let item_hir_id = if item. is_mod ( ) {
449
- if let Some ( def_id) = item. def_id . as_local ( ) {
450
- Some ( self . cx . tcx . hir ( ) . as_local_hir_id ( def_id) )
451
- } else {
452
- debug ! ( "attempting to fold on a non-local item: {:?}" , item) ;
453
- return self . fold_item_recur ( item) ;
454
- }
455
- } else {
456
- None
457
- } ;
458
-
459
449
let parent_node = if item. is_fake ( ) {
460
450
// FIXME: is this correct?
461
451
None
@@ -482,13 +472,9 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
482
472
let current_item = match item. inner {
483
473
ModuleItem ( ..) => {
484
474
if item. attrs . inner_docs {
485
- if item_hir_id . unwrap ( ) != hir :: CRATE_HIR_ID { item. name . clone ( ) } else { None }
475
+ if item . def_id . is_top_level_module ( ) { item. name . clone ( ) } else { None }
486
476
} else {
487
- match parent_node. or ( self
488
- . mod_ids
489
- . last ( )
490
- . map ( |& local| self . cx . tcx . hir ( ) . local_def_id ( local) . to_def_id ( ) ) )
491
- {
477
+ match parent_node. or ( self . mod_ids . last ( ) . copied ( ) ) {
492
478
Some ( parent) if !parent. is_top_level_module ( ) => {
493
479
// FIXME: can we pull the parent module's name from elsewhere?
494
480
Some ( self . cx . tcx . item_name ( parent) . to_string ( ) )
@@ -508,7 +494,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
508
494
} ;
509
495
510
496
if item. is_mod ( ) && item. attrs . inner_docs {
511
- self . mod_ids . push ( item_hir_id . unwrap ( ) ) ;
497
+ self . mod_ids . push ( item . def_id ) ;
512
498
}
513
499
514
500
let cx = self . cx ;
@@ -655,7 +641,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
655
641
// for outer comments we explicitly try and resolve against the
656
642
// parent_node first.
657
643
let base_node = if item. is_mod ( ) && item. attrs . inner_docs {
658
- self . mod_ids . last ( ) . map ( | & id| self . cx . tcx . hir ( ) . local_def_id ( id ) . to_def_id ( ) )
644
+ self . mod_ids . last ( ) . copied ( )
659
645
} else {
660
646
parent_node
661
647
} ;
@@ -842,7 +828,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
842
828
}
843
829
844
830
if item. is_mod ( ) && !item. attrs . inner_docs {
845
- self . mod_ids . push ( item_hir_id . unwrap ( ) ) ;
831
+ self . mod_ids . push ( item . def_id ) ;
846
832
}
847
833
848
834
if item. is_mod ( ) {
0 commit comments