Skip to content

Commit 24c3d85

Browse files
committed
Make sure that module_id is actually a module
1 parent 20106d5 commit 24c3d85

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,19 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
466466
// FIXME: is this correct?
467467
None
468468
} else {
469-
self.cx.tcx.parent(item.def_id)
469+
let mut current = item.def_id;
470+
// The immediate parent might not always be a module.
471+
// Find the first parent which is.
472+
loop {
473+
if let Some(parent) = self.cx.tcx.parent(current) {
474+
if self.cx.tcx.def_kind(parent) == DefKind::Mod {
475+
break Some(parent);
476+
}
477+
current = parent;
478+
} else {
479+
break None;
480+
}
481+
}
470482
};
471483

472484
if parent_node.is_some() {

0 commit comments

Comments
 (0)