@@ -175,94 +175,6 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
175175
176176 let cx = self . cx ;
177177
178- // In case this is a re-export, try to resolve the docs relative to the original module.
179- // Since we don't document `use` statements,
180- // we don't have to consider the case where an item is documented in both the original module and the current module.
181- /*
182- let mut module_id = None;
183- if let Some(item) = item_opt {
184- debug!("resolving {:?} with item kind {:?}", path_str, item.inner);
185- if let ItemEnum::ImportItem(import) = &item.inner {
186- if let Import::Simple(_, source) = import {
187- if let Some(def_id) = source.did {
188- use crate::rustc_middle::ty::DefIdTree;
189-
190- //let mut current_id = def_id;
191- if cx.tcx.def_kind(def_id) == DefKind::Mod {
192- module_id = Some(def_id);
193- debug!("found parent module {:?} for use statement", def_id);
194- //break;
195- } else {
196- debug!(
197- "not a module: {:?} (maybe an associated item?)",
198- cx.tcx.def_kind(def_id)
199- );
200- }
201-
202- /*
203- // For associated items, the parent module might be multiple nodes above
204- while let Some(parent) = cx.tcx.parent(current_id) {
205- if cx.tcx.def_kind(parent) == DefKind::Mod {
206- parent_id = Some(parent);
207- debug!("found parent module {:?} for use statement", parent);
208- break;
209- }
210- current_id = parent;
211- }
212- */
213- } else {
214- debug!("no def id found");
215- }
216- } else {
217- debug!("glob imports not handled for intra-doc links");
218- }
219- } else {
220- //debug!("item.inner not an import ({:?})", item.inner);
221- }
222- /*
223- if let Some(reexport) = item.reexport {
224- use crate::rustc_middle::ty::DefIdTree;
225-
226- let mut current_id = reexport;
227- // For associated items, the parent module might be multiple nodes above
228- while let Some(parent) = cx.tcx.parent(current_id) {
229- if cx.tcx.def_kind(parent) == DefKind::Mod {
230- parent_id = Some(parent);
231- debug!("found parent module {:?} for use statement", parent);
232- break;
233- }
234- current_id = parent;
235- }
236- }
237- */
238- /*
239- if let ItemKind::Use(path, use_kind) = item.kind {
240- if use_kind == UseKind::Single {
241- match path.res {
242- Res::Def(def_kind, def_id) => {
243- use crate::rustc_middle::ty::DefIdTree;
244-
245- let mut current_id = def_id;
246- // For associated items, the parent module might be multiple nodes above
247- while let Some(parent) = cx.tcx.parent(current_id) {
248- if cx.tcx.def_kind(parent) == DefKind::Mod {
249- parent_id = Some(parent);
250- debug!("found parent module {:?} for use statement", parent);
251- break;
252- }
253- current_id = parent;
254- }
255- }
256- _ => debug!("use {:?} was not a definition, not treating as cross-crate", item.name),
257- }
258- } else {
259- debug!("don't know how to resolve multiple imports for {:?}, not treating as cross-crate", path);
260- }
261- }
262- */
263- }
264- */
265-
266178 // In case we're in a module, try to resolve the relative path.
267179 if parent_id. is_none ( ) {
268180 let id = self . mod_ids . last ( ) . cloned ( ) ;
@@ -549,19 +461,13 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
549461 None
550462 } ;
551463
552- // FIXME: get the resolver to work with non-local resolve scopes.
553464 use rustc_middle:: ty:: DefIdTree ;
554- let parent_node = self . cx . tcx . parent ( item. def_id ) ;
555- /*
556- let parent_node = self.cx.as_local_hir_id(item.def_id).and_then(|hir_id| {
557- // FIXME: this fails hard for impls in non-module scope, but is necessary for the
558- // current `resolve()` implementation.
559- match self.cx.as_local_hir_id(self.cx.tcx.parent_module(hir_id).to_def_id()).unwrap() {
560- id if id != hir_id => Some(id),
561- _ => None,
562- }
563- });
564- */
465+ let parent_node = if item. is_fake ( ) {
466+ // FIXME: is this correct?
467+ None
468+ } else {
469+ self . cx . tcx . parent ( item. def_id )
470+ } ;
565471
566472 if parent_node. is_some ( ) {
567473 debug ! ( "got parent node for {:?} {:?}, id {:?}" , item. type_( ) , item. name, item. def_id) ;
@@ -572,7 +478,11 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
572478 if item. attrs . inner_docs {
573479 if item_hir_id. unwrap ( ) != hir:: CRATE_HIR_ID { item. name . clone ( ) } else { None }
574480 } else {
575- match parent_node. or ( self . mod_ids . last ( ) . map ( |& local| self . cx . tcx . hir ( ) . local_def_id ( local) . to_def_id ( ) ) ) {
481+ match parent_node. or ( self
482+ . mod_ids
483+ . last ( )
484+ . map ( |& local| self . cx . tcx . hir ( ) . local_def_id ( local) . to_def_id ( ) ) )
485+ {
576486 Some ( parent) if !parent. is_top_level_module ( ) => {
577487 // FIXME: can we pull the parent module's name from elsewhere?
578488 Some ( self . cx . tcx . item_name ( parent) . to_string ( ) )
0 commit comments