Add missing code to find_closest_parent_module
This commit is contained in:
parent
bb4761d1eb
commit
4b1b277cf9
@ -626,23 +626,31 @@ fn print_const_with_custom_print_scalar(cx: &DocContext<'_>, ct: &'tcx ty::Const
|
||||
}
|
||||
|
||||
crate fn find_closest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
|
||||
let mut current = def_id;
|
||||
// The immediate parent might not always be a module.
|
||||
// Find the first parent which is.
|
||||
loop {
|
||||
if let Some(parent) = tcx.parent(current) {
|
||||
if tcx.def_kind(parent) == DefKind::Mod {
|
||||
break Some(parent);
|
||||
if item.is_fake() {
|
||||
// FIXME: is this correct?
|
||||
None
|
||||
// If we're documenting the crate root itself, it has no parent. Use the root instead.
|
||||
} else if item.def_id.is_top_level_module() {
|
||||
Some(item.def_id)
|
||||
} else {
|
||||
let mut current = def_id;
|
||||
// The immediate parent might not always be a module.
|
||||
// Find the first parent which is.
|
||||
loop {
|
||||
if let Some(parent) = tcx.parent(current) {
|
||||
if tcx.def_kind(parent) == DefKind::Mod {
|
||||
break Some(parent);
|
||||
}
|
||||
current = parent;
|
||||
} else {
|
||||
debug!(
|
||||
"{:?} has no parent (kind={:?}, original was {:?})",
|
||||
current,
|
||||
tcx.def_kind(current),
|
||||
def_id
|
||||
);
|
||||
break None;
|
||||
}
|
||||
current = parent;
|
||||
} else {
|
||||
debug!(
|
||||
"{:?} has no parent (kind={:?}, original was {:?})",
|
||||
current,
|
||||
tcx.def_kind(current),
|
||||
def_id
|
||||
);
|
||||
break None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -767,15 +767,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
|
||||
fn fold_item(&mut self, mut item: Item) -> Option<Item> {
|
||||
use rustc_middle::ty::DefIdTree;
|
||||
|
||||
let parent_node = if item.is_fake() {
|
||||
// FIXME: is this correct?
|
||||
None
|
||||
// If we're documenting the crate root itself, it has no parent. Use the root instead.
|
||||
} else if item.def_id.is_top_level_module() {
|
||||
Some(item.def_id)
|
||||
} else {
|
||||
find_closest_parent_module(self.cx.tcx, item.def_id)
|
||||
};
|
||||
let parent_node = find_closest_parent_module(self.cx.tcx, item.def_id);
|
||||
|
||||
if parent_node.is_some() {
|
||||
trace!("got parent node for {:?} {:?}, id {:?}", item.type_(), item.name, item.def_id);
|
||||
|
Loading…
Reference in New Issue
Block a user