Skip to content

Commit e9ae18d

Browse files
camelidMark-Simulacrum
authored andcommitted
Update find_nearest_parent_module
1 parent 69e1722 commit e9ae18d

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/librustdoc/clean/utils.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,11 @@ where
625625
r
626626
}
627627

628-
crate fn find_closest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
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)
628+
/// Find the nearest parent module of a [`DefId`].
629+
crate fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
630+
if def_id.is_top_level_module() {
631+
// The crate root has no parent. Use it as the root instead.
632+
Some(def_id)
635633
} else {
636634
let mut current = def_id;
637635
// The immediate parent might not always be a module.

src/librustdoc/html/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::TyCtxt;
1515
use rustc_span::def_id::{DefId, CRATE_DEF_INDEX};
1616
use rustc_target::spec::abi::Abi;
1717

18-
use crate::clean::{self, utils::find_closest_parent_module, PrimitiveType};
18+
use crate::clean::{self, utils::find_nearest_parent_module, PrimitiveType};
1919
use crate::formats::cache::cache;
2020
use crate::formats::item_type::ItemType;
2121
use crate::html::escape::Escape;
@@ -1097,7 +1097,7 @@ impl clean::Visibility {
10971097
clean::Inherited => Ok(()),
10981098

10991099
clean::Visibility::Restricted(vis_did) => {
1100-
let parent_module = find_closest_parent_module(tcx, item_did);
1100+
let parent_module = find_nearest_parent_module(tcx, item_did);
11011101

11021102
if vis_did.index == CRATE_DEF_INDEX {
11031103
write!(f, "pub(crate) ")
@@ -1106,7 +1106,7 @@ impl clean::Visibility {
11061106
// is the same as no visibility modifier
11071107
Ok(())
11081108
} else if parent_module
1109-
.map(|parent| find_closest_parent_module(tcx, parent))
1109+
.map(|parent| find_nearest_parent_module(tcx, parent))
11101110
.flatten()
11111111
== Some(vis_did)
11121112
{

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::cell::Cell;
3131
use std::mem;
3232
use std::ops::Range;
3333

34-
use crate::clean::{self, utils::find_closest_parent_module, Crate, Item, ItemLink, PrimitiveType};
34+
use crate::clean::{self, utils::find_nearest_parent_module, Crate, Item, ItemLink, PrimitiveType};
3535
use crate::core::DocContext;
3636
use crate::fold::DocFolder;
3737
use crate::html::markdown::markdown_links;
@@ -767,7 +767,12 @@ 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 = find_closest_parent_module(self.cx.tcx, item.def_id);
770+
let parent_node = if item.is_fake() {
771+
// FIXME: is this correct?
772+
None
773+
} else {
774+
find_nearest_parent_module(self.cx.tcx, item.def_id)
775+
};
771776

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

0 commit comments

Comments
 (0)