Skip to content

Commit 35e7bee

Browse files
committed
Get rid of doctree::ForeignItem
1 parent 53d19b3 commit 35e7bee

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

src/librustdoc/clean/mod.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -2186,11 +2186,12 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
21862186
}
21872187
}
21882188

2189-
impl Clean<Item> for doctree::ForeignItem<'_> {
2189+
impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Ident>) {
21902190
fn clean(&self, cx: &DocContext<'_>) -> Item {
2191-
let kind = match self.kind {
2191+
let (item, renamed) = self;
2192+
let kind = match item.kind {
21922193
hir::ForeignItemKind::Fn(ref decl, ref names, ref generics) => {
2193-
let abi = cx.tcx.hir().get_foreign_abi(self.id);
2194+
let abi = cx.tcx.hir().get_foreign_abi(item.hir_id);
21942195
let (generics, decl) =
21952196
enter_impl_trait(cx, || (generics.clean(cx), (&**decl, &names[..]).clean(cx)));
21962197
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
@@ -2207,15 +2208,13 @@ impl Clean<Item> for doctree::ForeignItem<'_> {
22072208
ret_types,
22082209
})
22092210
}
2210-
hir::ForeignItemKind::Static(ref ty, mutbl) => ForeignStaticItem(Static {
2211-
type_: ty.clean(cx),
2212-
mutability: *mutbl,
2213-
expr: String::new(),
2214-
}),
2211+
hir::ForeignItemKind::Static(ref ty, mutability) => {
2212+
ForeignStaticItem(Static { type_: ty.clean(cx), mutability, expr: String::new() })
2213+
}
22152214
hir::ForeignItemKind::Type => ForeignTypeItem,
22162215
};
22172216

2218-
Item::from_hir_id_and_parts(self.id, Some(self.name), kind, cx)
2217+
Item::from_hir_id_and_parts(item.hir_id, Some(renamed.unwrap_or(item.ident).name), kind, cx)
22192218
}
22202219
}
22212220

src/librustdoc/doctree.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ crate struct Module<'hir> {
2323
// (item, renamed)
2424
crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
2525
crate traits: Vec<Trait<'hir>>,
26-
crate foreigns: Vec<ForeignItem<'hir>>,
26+
crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
2727
crate macros: Vec<Macro>,
2828
crate proc_macros: Vec<ProcMacro>,
2929
crate is_crate: bool,
@@ -87,12 +87,6 @@ crate struct Trait<'hir> {
8787
crate id: hir::HirId,
8888
}
8989

90-
crate struct ForeignItem<'hir> {
91-
crate id: hir::HirId,
92-
crate name: Symbol,
93-
crate kind: &'hir hir::ForeignItemKind<'hir>,
94-
}
95-
9690
// For Macro we store the DefId instead of the NodeId, since we also create
9791
// these imported macro_rules (which only have a DUMMY_NODE_ID).
9892
crate struct Macro {

src/librustdoc/visit_ast.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
418418
om: &mut Module<'tcx>,
419419
) {
420420
// If inlining we only want to include public functions.
421-
if self.inlining && !item.vis.node.is_pub() {
422-
return;
421+
if !self.inlining || item.vis.node.is_pub() {
422+
om.foreigns.push((item, renamed));
423423
}
424-
425-
om.foreigns.push(ForeignItem {
426-
id: item.hir_id,
427-
name: renamed.unwrap_or(item.ident).name,
428-
kind: &item.kind,
429-
});
430424
}
431425

432426
// Convert each `exported_macro` into a doc item.

0 commit comments

Comments
 (0)