From 2a58fa06827f2b824176ed01643bd76852a2028a Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 22 Nov 2020 21:32:18 -0500 Subject: [PATCH] Get rid of doctree::Trait --- src/librustdoc/clean/mod.rs | 35 ++++++++++++++--------------------- src/librustdoc/doctree.rs | 13 ------------- src/librustdoc/visit_ast.rs | 15 +-------------- 3 files changed, 15 insertions(+), 48 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 752918250d8..ac02818224b 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -234,7 +234,6 @@ fn clean(&self, cx: &DocContext<'_>) -> Item { 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 @@ -1022,26 +1021,6 @@ fn clean(&self, cx: &DocContext<'_>) -> FnRetTy { } } -impl Clean 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 for hir::IsAuto { fn clean(&self, _: &DocContext<'_>) -> bool { match *self { @@ -2011,6 +1990,20 @@ fn clean(&self, cx: &DocContext<'_>) -> Vec { 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"), }; diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index c6c11164e7d..6bcd6f0c1e9 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -20,7 +20,6 @@ crate id: hir::HirId, // (item, renamed) crate items: Vec<(&'hir hir::Item<'hir>, Option)>, - crate traits: Vec>, crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option)>, crate macros: Vec, crate is_crate: bool, @@ -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, @@ -62,17 +60,6 @@ impl Module<'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 { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 624d4d07cc0..d9326b56e9c 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -319,6 +319,7 @@ fn visit_item( | 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 @@ -327,20 +328,6 @@ fn visit_item( 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.