@@ -167,7 +167,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
167
167
disambiguator : Option < & str > ,
168
168
ns : Namespace ,
169
169
current_item : & Option < String > ,
170
- mut parent_id : Option < hir :: HirId > ,
170
+ mut parent_id : Option < DefId > ,
171
171
extra_fragment : & Option < String > ,
172
172
item_opt : Option < & Item > ,
173
173
) -> Result < ( Res , Option < String > ) , ErrorKind > {
@@ -178,8 +178,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
178
178
// In case this is a re-export, try to resolve the docs relative to the original module.
179
179
// Since we don't document `use` statements,
180
180
// we don't have to consider the case where an item is documented in both the original module and the current module.
181
+ /*
181
182
let mut module_id = None;
182
183
if let Some(item) = item_opt {
184
+ debug!("resolving {:?} with item kind {:?}", path_str, item.inner);
183
185
if let ItemEnum::ImportItem(import) = &item.inner {
184
186
if let Import::Simple(_, source) = import {
185
187
if let Some(def_id) = source.did {
@@ -214,6 +216,8 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
214
216
} else {
215
217
debug!("glob imports not handled for intra-doc links");
216
218
}
219
+ } else {
220
+ //debug!("item.inner not an import ({:?})", item.inner);
217
221
}
218
222
/*
219
223
if let Some(reexport) = item.reexport {
@@ -257,13 +261,14 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
257
261
}
258
262
*/
259
263
}
264
+ */
260
265
261
266
// In case we're in a module, try to resolve the relative path.
262
- if module_id . is_none ( ) {
263
- let id = parent_id . or ( self . mod_ids . last ( ) . cloned ( ) ) ;
264
- module_id = id. map ( |id| cx. tcx . hir ( ) . local_def_id ( id) . to_def_id ( ) ) ;
267
+ if parent_id . is_none ( ) {
268
+ let id = self . mod_ids . last ( ) . cloned ( ) ;
269
+ parent_id = id. map ( |id| cx. tcx . hir ( ) . local_def_id ( id) . to_def_id ( ) ) ;
265
270
}
266
- if let Some ( module_id) = module_id {
271
+ if let Some ( module_id) = parent_id {
267
272
let result = cx. enter_resolver ( |resolver| {
268
273
resolver. resolve_str_path_error ( DUMMY_SP , & path_str, ns, module_id)
269
274
} ) ;
@@ -545,6 +550,9 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
545
550
} ;
546
551
547
552
// FIXME: get the resolver to work with non-local resolve scopes.
553
+ use rustc_middle:: ty:: DefIdTree ;
554
+ let parent_node = self . cx . tcx . parent ( item. def_id ) ;
555
+ /*
548
556
let parent_node = self.cx.as_local_hir_id(item.def_id).and_then(|hir_id| {
549
557
// FIXME: this fails hard for impls in non-module scope, but is necessary for the
550
558
// current `resolve()` implementation.
@@ -553,6 +561,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
553
561
_ => None,
554
562
}
555
563
});
564
+ */
556
565
557
566
if parent_node. is_some ( ) {
558
567
debug ! ( "got parent node for {:?} {:?}, id {:?}" , item. type_( ) , item. name, item. def_id) ;
@@ -563,10 +572,10 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
563
572
if item. attrs . inner_docs {
564
573
if item_hir_id. unwrap ( ) != hir:: CRATE_HIR_ID { item. name . clone ( ) } else { None }
565
574
} else {
566
- match parent_node. or ( self . mod_ids . last ( ) . cloned ( ) ) {
567
- Some ( parent) if parent != hir :: CRATE_HIR_ID => {
575
+ match parent_node. or ( self . mod_ids . last ( ) . map ( | & local| self . cx . tcx . hir ( ) . local_def_id ( local ) . to_def_id ( ) ) ) {
576
+ Some ( parent) if !parent . is_top_level_module ( ) => {
568
577
// FIXME: can we pull the parent module's name from elsewhere?
569
- Some ( self . cx . tcx . hir ( ) . name ( parent) . to_string ( ) )
578
+ Some ( self . cx . tcx . item_name ( parent) . to_string ( ) )
570
579
}
571
580
_ => None ,
572
581
}
0 commit comments