Skip to content

Commit 69bd13f

Browse files
committed
Use DefId for modules
1 parent 848a766 commit 69bd13f

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
167167
disambiguator: Option<&str>,
168168
ns: Namespace,
169169
current_item: &Option<String>,
170-
mut parent_id: Option<hir::HirId>,
170+
mut parent_id: Option<DefId>,
171171
extra_fragment: &Option<String>,
172172
item_opt: Option<&Item>,
173173
) -> Result<(Res, Option<String>), ErrorKind> {
@@ -178,8 +178,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
178178
// In case this is a re-export, try to resolve the docs relative to the original module.
179179
// Since we don't document `use` statements,
180180
// we don't have to consider the case where an item is documented in both the original module and the current module.
181+
/*
181182
let mut module_id = None;
182183
if let Some(item) = item_opt {
184+
debug!("resolving {:?} with item kind {:?}", path_str, item.inner);
183185
if let ItemEnum::ImportItem(import) = &item.inner {
184186
if let Import::Simple(_, source) = import {
185187
if let Some(def_id) = source.did {
@@ -214,6 +216,8 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
214216
} else {
215217
debug!("glob imports not handled for intra-doc links");
216218
}
219+
} else {
220+
//debug!("item.inner not an import ({:?})", item.inner);
217221
}
218222
/*
219223
if let Some(reexport) = item.reexport {
@@ -257,13 +261,14 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
257261
}
258262
*/
259263
}
264+
*/
260265

261266
// 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());
265270
}
266-
if let Some(module_id) = module_id {
271+
if let Some(module_id) = parent_id {
267272
let result = cx.enter_resolver(|resolver| {
268273
resolver.resolve_str_path_error(DUMMY_SP, &path_str, ns, module_id)
269274
});
@@ -545,6 +550,9 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
545550
};
546551

547552
// 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+
/*
548556
let parent_node = self.cx.as_local_hir_id(item.def_id).and_then(|hir_id| {
549557
// FIXME: this fails hard for impls in non-module scope, but is necessary for the
550558
// current `resolve()` implementation.
@@ -553,6 +561,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
553561
_ => None,
554562
}
555563
});
564+
*/
556565

557566
if parent_node.is_some() {
558567
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> {
563572
if item.attrs.inner_docs {
564573
if item_hir_id.unwrap() != hir::CRATE_HIR_ID { item.name.clone() } else { None }
565574
} 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() => {
568577
// 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())
570579
}
571580
_ => None,
572581
}

0 commit comments

Comments
 (0)