Skip to content

Commit c7a85ca

Browse files
camelidMark-Simulacrum
authored andcommitted
Add missing code to find_closest_parent_module
1 parent c73576a commit c7a85ca

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

src/librustdoc/clean/utils.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -626,23 +626,31 @@ where
626626
}
627627

628628
crate fn find_closest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
629-
let mut current = def_id;
630-
// The immediate parent might not always be a module.
631-
// Find the first parent which is.
632-
loop {
633-
if let Some(parent) = tcx.parent(current) {
634-
if tcx.def_kind(parent) == DefKind::Mod {
635-
break Some(parent);
629+
if item.is_fake() {
630+
// FIXME: is this correct?
631+
None
632+
// If we're documenting the crate root itself, it has no parent. Use the root instead.
633+
} else if item.def_id.is_top_level_module() {
634+
Some(item.def_id)
635+
} else {
636+
let mut current = def_id;
637+
// The immediate parent might not always be a module.
638+
// Find the first parent which is.
639+
loop {
640+
if let Some(parent) = tcx.parent(current) {
641+
if tcx.def_kind(parent) == DefKind::Mod {
642+
break Some(parent);
643+
}
644+
current = parent;
645+
} else {
646+
debug!(
647+
"{:?} has no parent (kind={:?}, original was {:?})",
648+
current,
649+
tcx.def_kind(current),
650+
def_id
651+
);
652+
break None;
636653
}
637-
current = parent;
638-
} else {
639-
debug!(
640-
"{:?} has no parent (kind={:?}, original was {:?})",
641-
current,
642-
tcx.def_kind(current),
643-
def_id
644-
);
645-
break None;
646654
}
647655
}
648656
}

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -767,15 +767,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
767767
fn fold_item(&mut self, mut item: Item) -> Option<Item> {
768768
use rustc_middle::ty::DefIdTree;
769769

770-
let parent_node = if item.is_fake() {
771-
// FIXME: is this correct?
772-
None
773-
// If we're documenting the crate root itself, it has no parent. Use the root instead.
774-
} else if item.def_id.is_top_level_module() {
775-
Some(item.def_id)
776-
} else {
777-
find_closest_parent_module(self.cx.tcx, item.def_id)
778-
};
770+
let parent_node = find_closest_parent_module(self.cx.tcx, item.def_id);
779771

780772
if parent_node.is_some() {
781773
trace!("got parent node for {:?} {:?}, id {:?}", item.type_(), item.name, item.def_id);

0 commit comments

Comments
 (0)