Skip to content

Commit

Permalink
Get rid of doctree::ForeignItem
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Nov 23, 2020
1 parent 8de207e commit 090fc51
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
17 changes: 8 additions & 9 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2186,11 +2186,12 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
}
}

impl Clean<Item> for doctree::ForeignItem<'_> {
impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Ident>) {
fn clean(&self, cx: &DocContext<'_>) -> Item {
let kind = match self.kind {
let (item, renamed) = self;
let kind = match item.kind {
hir::ForeignItemKind::Fn(ref decl, ref names, ref generics) => {
let abi = cx.tcx.hir().get_foreign_abi(self.id);
let abi = cx.tcx.hir().get_foreign_abi(item.hir_id);
let (generics, decl) =
enter_impl_trait(cx, || (generics.clean(cx), (&**decl, &names[..]).clean(cx)));
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
Expand All @@ -2207,15 +2208,13 @@ impl Clean<Item> for doctree::ForeignItem<'_> {
ret_types,
})
}
hir::ForeignItemKind::Static(ref ty, mutbl) => ForeignStaticItem(Static {
type_: ty.clean(cx),
mutability: *mutbl,
expr: String::new(),
}),
hir::ForeignItemKind::Static(ref ty, mutability) => {
ForeignStaticItem(Static { type_: ty.clean(cx), mutability, expr: String::new() })
}
hir::ForeignItemKind::Type => ForeignTypeItem,
};

Item::from_hir_id_and_parts(self.id, Some(self.name), kind, cx)
Item::from_hir_id_and_parts(item.hir_id, Some(renamed.unwrap_or(item.ident).name), kind, cx)
}
}

Expand Down
8 changes: 1 addition & 7 deletions src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ crate struct Module<'hir> {
// (item, renamed)
crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
crate traits: Vec<Trait<'hir>>,
crate foreigns: Vec<ForeignItem<'hir>>,
crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
crate macros: Vec<Macro>,
crate proc_macros: Vec<ProcMacro>,
crate is_crate: bool,
Expand Down Expand Up @@ -87,12 +87,6 @@ crate struct Trait<'hir> {
crate id: hir::HirId,
}

crate struct ForeignItem<'hir> {
crate id: hir::HirId,
crate name: Symbol,
crate kind: &'hir hir::ForeignItemKind<'hir>,
}

// For Macro we store the DefId instead of the NodeId, since we also create
// these imported macro_rules (which only have a DUMMY_NODE_ID).
crate struct Macro {
Expand Down
10 changes: 2 additions & 8 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
om: &mut Module<'tcx>,
) {
// If inlining we only want to include public functions.
if self.inlining && !item.vis.node.is_pub() {
return;
if !self.inlining || item.vis.node.is_pub() {
om.foreigns.push((item, renamed));
}

om.foreigns.push(ForeignItem {
id: item.hir_id,
name: renamed.unwrap_or(item.ident).name,
kind: &item.kind,
});
}

// Convert each `exported_macro` into a doc item.
Expand Down

0 comments on commit 090fc51

Please sign in to comment.