Skip to content

Commit

Permalink
Get rid of doctree::Trait
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Nov 24, 2020
1 parent a3a5d2c commit 2a58fa0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 48 deletions.
35 changes: 14 additions & 21 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ impl Clean<Item> for doctree::Module<'_> {
items.extend(self.foreigns.iter().map(|x| x.clean(cx)));
items.extend(self.mods.iter().map(|x| x.clean(cx)));
items.extend(self.items.iter().map(|x| x.clean(cx)).flatten());
items.extend(self.traits.iter().map(|x| x.clean(cx)));
items.extend(self.macros.iter().map(|x| x.clean(cx)));

// determine if we should display the inner contents or
Expand Down Expand Up @@ -1022,26 +1021,6 @@ impl Clean<FnRetTy> for hir::FnRetTy<'_> {
}
}

impl Clean<Item> for doctree::Trait<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
let attrs = self.attrs.clean(cx);
let is_spotlight = attrs.has_doc_flag(sym::spotlight);
Item::from_hir_id_and_parts(
self.id,
Some(self.name),
TraitItem(Trait {
unsafety: self.unsafety,
items: self.items.iter().map(|ti| ti.clean(cx)).collect(),
generics: self.generics.clean(cx),
bounds: self.bounds.clean(cx),
is_spotlight,
is_auto: self.is_auto.clean(cx),
}),
cx,
)
}
}

impl Clean<bool> for hir::IsAuto {
fn clean(&self, _: &DocContext<'_>) -> bool {
match *self {
Expand Down Expand Up @@ -2011,6 +1990,20 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Ident>) {
ItemKind::Fn(ref sig, ref generics, body_id) => {
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
}
hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {
let items =
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();
let attrs = item.attrs.clean(cx);
let is_spotlight = attrs.has_doc_flag(sym::spotlight);
TraitItem(Trait {
unsafety,
items,
generics: generics.clean(cx),
bounds: bounds.clean(cx),
is_spotlight,
is_auto: is_auto.clean(cx),
})
}
_ => unreachable!("not yet converted"),
};

Expand Down
13 changes: 0 additions & 13 deletions src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ crate struct Module<'hir> {
crate id: hir::HirId,
// (item, renamed)
crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
crate traits: Vec<Trait<'hir>>,
crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
crate macros: Vec<Macro>,
crate is_crate: bool,
Expand All @@ -38,7 +37,6 @@ impl Module<'hir> {
imports: Vec::new(),
mods: Vec::new(),
items: Vec::new(),
traits: Vec::new(),
foreigns: Vec::new(),
macros: Vec::new(),
is_crate: false,
Expand All @@ -62,17 +60,6 @@ crate struct Variant<'hir> {
crate def: &'hir hir::VariantData<'hir>,
}

crate struct Trait<'hir> {
crate is_auto: hir::IsAuto,
crate unsafety: hir::Unsafety,
crate name: Symbol,
crate items: Vec<&'hir hir::TraitItem<'hir>>,
crate generics: &'hir hir::Generics<'hir>,
crate bounds: &'hir [hir::GenericBound<'hir>],
crate attrs: &'hir [ast::Attribute],
crate id: hir::HirId,
}

// 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
15 changes: 1 addition & 14 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
| hir::ItemKind::TyAlias(..)
| hir::ItemKind::OpaqueTy(..)
| hir::ItemKind::Static(..)
| hir::ItemKind::Trait(..)
| hir::ItemKind::TraitAlias(..) => om.items.push((item, renamed)),
hir::ItemKind::Const(..) => {
// Underscore constants do not correspond to a nameable item and
Expand All @@ -327,20 +328,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
om.items.push((item, renamed));
}
}
hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {
let items = item_ids.iter().map(|ti| self.cx.tcx.hir().trait_item(ti.id)).collect();
let t = Trait {
is_auto,
unsafety,
name: ident.name,
items,
generics,
bounds,
id: item.hir_id,
attrs: &item.attrs,
};
om.traits.push(t);
}
hir::ItemKind::Impl { ref of_trait, .. } => {
// Don't duplicate impls when inlining or if it's implementing a trait, we'll pick
// them up regardless of where they're located.
Expand Down

0 comments on commit 2a58fa0

Please sign in to comment.