1
Fork 0

Remove dead code in rustdoc::doctree

It was completely unused.
This commit is contained in:
Joshua Nelson 2020-11-14 18:27:06 -05:00
parent fc4ca55291
commit 0e1a302f59
3 changed files with 18 additions and 147 deletions

View file

@ -2280,7 +2280,7 @@ impl Clean<Item> for doctree::ForeignItem<'_> {
} }
} }
impl Clean<Item> for doctree::Macro<'_> { impl Clean<Item> for doctree::Macro {
fn clean(&self, cx: &DocContext<'_>) -> Item { fn clean(&self, cx: &DocContext<'_>) -> Item {
Item::from_def_id_and_parts( Item::from_def_id_and_parts(
self.def_id, self.def_id,
@ -2301,7 +2301,7 @@ impl Clean<Item> for doctree::Macro<'_> {
} }
} }
impl Clean<Item> for doctree::ProcMacro<'_> { impl Clean<Item> for doctree::ProcMacro {
fn clean(&self, cx: &DocContext<'_>) -> Item { fn clean(&self, cx: &DocContext<'_>) -> Item {
Item::from_hir_id_and_parts( Item::from_hir_id_and_parts(
self.id, self.id,

View file

@ -28,25 +28,19 @@ crate struct Module<'hir> {
crate statics: Vec<Static<'hir>>, crate statics: Vec<Static<'hir>>,
crate constants: Vec<Constant<'hir>>, crate constants: Vec<Constant<'hir>>,
crate traits: Vec<Trait<'hir>>, crate traits: Vec<Trait<'hir>>,
crate vis: &'hir hir::Visibility<'hir>,
crate impls: Vec<Impl<'hir>>, crate impls: Vec<Impl<'hir>>,
crate foreigns: Vec<ForeignItem<'hir>>, crate foreigns: Vec<ForeignItem<'hir>>,
crate macros: Vec<Macro<'hir>>, crate macros: Vec<Macro>,
crate proc_macros: Vec<ProcMacro<'hir>>, crate proc_macros: Vec<ProcMacro>,
crate trait_aliases: Vec<TraitAlias<'hir>>, crate trait_aliases: Vec<TraitAlias<'hir>>,
crate is_crate: bool, crate is_crate: bool,
} }
impl Module<'hir> { impl Module<'hir> {
crate fn new( crate fn new(name: Option<Symbol>, attrs: &'hir [ast::Attribute]) -> Module<'hir> {
name: Option<Symbol>,
attrs: &'hir [ast::Attribute],
vis: &'hir hir::Visibility<'hir>,
) -> Module<'hir> {
Module { Module {
name, name,
id: hir::CRATE_HIR_ID, id: hir::CRATE_HIR_ID,
vis,
where_outer: rustc_span::DUMMY_SP, where_outer: rustc_span::DUMMY_SP,
where_inner: rustc_span::DUMMY_SP, where_inner: rustc_span::DUMMY_SP,
attrs, attrs,
@ -83,53 +77,39 @@ crate enum StructType {
} }
crate struct Struct<'hir> { crate struct Struct<'hir> {
crate vis: &'hir hir::Visibility<'hir>,
crate id: hir::HirId, crate id: hir::HirId,
crate struct_type: StructType, crate struct_type: StructType,
crate name: Symbol, crate name: Symbol,
crate generics: &'hir hir::Generics<'hir>, crate generics: &'hir hir::Generics<'hir>,
crate attrs: &'hir [ast::Attribute],
crate fields: &'hir [hir::StructField<'hir>], crate fields: &'hir [hir::StructField<'hir>],
crate span: Span,
} }
crate struct Union<'hir> { crate struct Union<'hir> {
crate vis: &'hir hir::Visibility<'hir>,
crate id: hir::HirId, crate id: hir::HirId,
crate struct_type: StructType, crate struct_type: StructType,
crate name: Symbol, crate name: Symbol,
crate generics: &'hir hir::Generics<'hir>, crate generics: &'hir hir::Generics<'hir>,
crate attrs: &'hir [ast::Attribute],
crate fields: &'hir [hir::StructField<'hir>], crate fields: &'hir [hir::StructField<'hir>],
crate span: Span,
} }
crate struct Enum<'hir> { crate struct Enum<'hir> {
crate vis: &'hir hir::Visibility<'hir>,
crate variants: Vec<Variant<'hir>>, crate variants: Vec<Variant<'hir>>,
crate generics: &'hir hir::Generics<'hir>, crate generics: &'hir hir::Generics<'hir>,
crate attrs: &'hir [ast::Attribute],
crate id: hir::HirId, crate id: hir::HirId,
crate span: Span,
crate name: Symbol, crate name: Symbol,
} }
crate struct Variant<'hir> { crate struct Variant<'hir> {
crate name: Symbol, crate name: Symbol,
crate id: hir::HirId, crate id: hir::HirId,
crate attrs: &'hir [ast::Attribute],
crate def: &'hir hir::VariantData<'hir>, crate def: &'hir hir::VariantData<'hir>,
crate span: Span,
} }
crate struct Function<'hir> { crate struct Function<'hir> {
crate decl: &'hir hir::FnDecl<'hir>, crate decl: &'hir hir::FnDecl<'hir>,
crate attrs: &'hir [ast::Attribute],
crate id: hir::HirId, crate id: hir::HirId,
crate name: Symbol, crate name: Symbol,
crate vis: &'hir hir::Visibility<'hir>,
crate header: hir::FnHeader, crate header: hir::FnHeader,
crate span: Span,
crate generics: &'hir hir::Generics<'hir>, crate generics: &'hir hir::Generics<'hir>,
crate body: hir::BodyId, crate body: hir::BodyId,
} }
@ -139,18 +119,12 @@ crate struct Typedef<'hir> {
crate gen: &'hir hir::Generics<'hir>, crate gen: &'hir hir::Generics<'hir>,
crate name: Symbol, crate name: Symbol,
crate id: hir::HirId, crate id: hir::HirId,
crate attrs: &'hir [ast::Attribute],
crate span: Span,
crate vis: &'hir hir::Visibility<'hir>,
} }
crate struct OpaqueTy<'hir> { crate struct OpaqueTy<'hir> {
crate opaque_ty: &'hir hir::OpaqueTy<'hir>, crate opaque_ty: &'hir hir::OpaqueTy<'hir>,
crate name: Symbol, crate name: Symbol,
crate id: hir::HirId, crate id: hir::HirId,
crate attrs: &'hir [ast::Attribute],
crate span: Span,
crate vis: &'hir hir::Visibility<'hir>,
} }
#[derive(Debug)] #[derive(Debug)]
@ -169,10 +143,7 @@ crate struct Constant<'hir> {
crate type_: &'hir hir::Ty<'hir>, crate type_: &'hir hir::Ty<'hir>,
crate expr: hir::BodyId, crate expr: hir::BodyId,
crate name: Symbol, crate name: Symbol,
crate attrs: &'hir [ast::Attribute],
crate vis: &'hir hir::Visibility<'hir>,
crate id: hir::HirId, crate id: hir::HirId,
crate span: Span,
} }
crate struct Trait<'hir> { crate struct Trait<'hir> {
@ -184,18 +155,13 @@ crate struct Trait<'hir> {
crate bounds: &'hir [hir::GenericBound<'hir>], crate bounds: &'hir [hir::GenericBound<'hir>],
crate attrs: &'hir [ast::Attribute], crate attrs: &'hir [ast::Attribute],
crate id: hir::HirId, crate id: hir::HirId,
crate span: Span,
crate vis: &'hir hir::Visibility<'hir>,
} }
crate struct TraitAlias<'hir> { crate struct TraitAlias<'hir> {
crate name: Symbol, crate name: Symbol,
crate generics: &'hir hir::Generics<'hir>, crate generics: &'hir hir::Generics<'hir>,
crate bounds: &'hir [hir::GenericBound<'hir>], crate bounds: &'hir [hir::GenericBound<'hir>],
crate attrs: &'hir [ast::Attribute],
crate id: hir::HirId, crate id: hir::HirId,
crate span: Span,
crate vis: &'hir hir::Visibility<'hir>,
} }
#[derive(Debug)] #[derive(Debug)]
@ -215,22 +181,16 @@ crate struct Impl<'hir> {
} }
crate struct ForeignItem<'hir> { crate struct ForeignItem<'hir> {
crate vis: &'hir hir::Visibility<'hir>,
crate id: hir::HirId, crate id: hir::HirId,
crate name: Symbol, crate name: Symbol,
crate kind: &'hir hir::ForeignItemKind<'hir>, crate kind: &'hir hir::ForeignItemKind<'hir>,
crate attrs: &'hir [ast::Attribute],
crate span: Span,
} }
// For Macro we store the DefId instead of the NodeId, since we also create // 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). // these imported macro_rules (which only have a DUMMY_NODE_ID).
crate struct Macro<'hir> { crate struct Macro {
crate name: Symbol, crate name: Symbol,
crate hid: hir::HirId,
crate def_id: hir::def_id::DefId, crate def_id: hir::def_id::DefId,
crate attrs: &'hir [ast::Attribute],
crate span: Span,
crate matchers: Vec<Span>, crate matchers: Vec<Span>,
crate imported_from: Option<Symbol>, crate imported_from: Option<Symbol>,
} }
@ -256,13 +216,11 @@ crate struct Import<'hir> {
crate span: Span, crate span: Span,
} }
crate struct ProcMacro<'hir> { crate struct ProcMacro {
crate name: Symbol, crate name: Symbol,
crate id: hir::HirId, crate id: hir::HirId,
crate kind: MacroKind, crate kind: MacroKind,
crate helpers: Vec<Symbol>, crate helpers: Vec<Symbol>,
crate attrs: &'hir [ast::Attribute],
crate span: Span,
} }
crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType { crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {

View file

@ -91,16 +91,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
) -> Struct<'tcx> { ) -> Struct<'tcx> {
debug!("visiting struct"); debug!("visiting struct");
let struct_type = struct_type_from_def(&*sd); let struct_type = struct_type_from_def(&*sd);
Struct { Struct { id: item.hir_id, struct_type, name, generics, fields: sd.fields() }
id: item.hir_id,
struct_type,
name,
vis: &item.vis,
attrs: &item.attrs,
generics,
fields: sd.fields(),
span: item.span,
}
} }
fn visit_union_data( fn visit_union_data(
@ -112,16 +103,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
) -> Union<'tcx> { ) -> Union<'tcx> {
debug!("visiting union"); debug!("visiting union");
let struct_type = struct_type_from_def(&*sd); let struct_type = struct_type_from_def(&*sd);
Union { Union { id: item.hir_id, struct_type, name, generics, fields: sd.fields() }
id: item.hir_id,
struct_type,
name,
vis: &item.vis,
attrs: &item.attrs,
generics,
fields: sd.fields(),
span: item.span,
}
} }
fn visit_enum_def( fn visit_enum_def(
@ -137,19 +119,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
variants: def variants: def
.variants .variants
.iter() .iter()
.map(|v| Variant { .map(|v| Variant { name: v.ident.name, id: v.id, def: &v.data })
name: v.ident.name,
id: v.id,
attrs: &v.attrs,
def: &v.data,
span: v.span,
})
.collect(), .collect(),
vis: &it.vis,
generics, generics,
attrs: &it.attrs,
id: it.hir_id, id: it.hir_id,
span: it.span,
} }
} }
@ -202,27 +175,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
} }
} }
om.proc_macros.push(ProcMacro { om.proc_macros.push(ProcMacro { name, id: item.hir_id, kind, helpers });
name,
id: item.hir_id,
kind,
helpers,
attrs: &item.attrs,
span: item.span,
});
} }
None => { None => {
om.fns.push(Function { om.fns.push(Function { id: item.hir_id, decl, name, generics, header, body });
id: item.hir_id,
vis: &item.vis,
attrs: &item.attrs,
decl,
name,
span: item.span,
generics,
header,
body,
});
} }
} }
} }
@ -236,7 +192,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
m: &'tcx hir::Mod<'tcx>, m: &'tcx hir::Mod<'tcx>,
name: Option<Symbol>, name: Option<Symbol>,
) -> Module<'tcx> { ) -> Module<'tcx> {
let mut om = Module::new(name, attrs, vis); let mut om = Module::new(name, attrs);
om.where_outer = span; om.where_outer = span;
om.where_inner = m.inner; om.where_inner = m.inner;
om.id = id; om.id = id;
@ -471,26 +427,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
self.visit_fn(om, item, ident.name, &sig.decl, sig.header, gen, body) self.visit_fn(om, item, ident.name, &sig.decl, sig.header, gen, body)
} }
hir::ItemKind::TyAlias(ty, ref gen) => { hir::ItemKind::TyAlias(ty, ref gen) => {
let t = Typedef { let t = Typedef { ty, gen, name: ident.name, id: item.hir_id };
ty,
gen,
name: ident.name,
id: item.hir_id,
attrs: &item.attrs,
span: item.span,
vis: &item.vis,
};
om.typedefs.push(t); om.typedefs.push(t);
} }
hir::ItemKind::OpaqueTy(ref opaque_ty) => { hir::ItemKind::OpaqueTy(ref opaque_ty) => {
let t = OpaqueTy { let t = OpaqueTy { opaque_ty, name: ident.name, id: item.hir_id };
opaque_ty,
name: ident.name,
id: item.hir_id,
attrs: &item.attrs,
span: item.span,
vis: &item.vis,
};
om.opaque_tys.push(t); om.opaque_tys.push(t);
} }
hir::ItemKind::Static(type_, mutability, expr) => { hir::ItemKind::Static(type_, mutability, expr) => {
@ -510,15 +451,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// Underscore constants do not correspond to a nameable item and // Underscore constants do not correspond to a nameable item and
// so are never useful in documentation. // so are never useful in documentation.
if ident.name != kw::Underscore { if ident.name != kw::Underscore {
let s = Constant { let s = Constant { type_, expr, id: item.hir_id, name: ident.name };
type_,
expr,
id: item.hir_id,
name: ident.name,
attrs: &item.attrs,
span: item.span,
vis: &item.vis,
};
om.constants.push(s); om.constants.push(s);
} }
} }
@ -533,21 +466,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
bounds, bounds,
id: item.hir_id, id: item.hir_id,
attrs: &item.attrs, attrs: &item.attrs,
span: item.span,
vis: &item.vis,
}; };
om.traits.push(t); om.traits.push(t);
} }
hir::ItemKind::TraitAlias(ref generics, ref bounds) => { hir::ItemKind::TraitAlias(ref generics, ref bounds) => {
let t = TraitAlias { let t = TraitAlias { name: ident.name, generics, bounds, id: item.hir_id };
name: ident.name,
generics,
bounds,
id: item.hir_id,
attrs: &item.attrs,
span: item.span,
vis: &item.vis,
};
om.trait_aliases.push(t); om.trait_aliases.push(t);
} }
@ -602,29 +525,19 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
id: item.hir_id, id: item.hir_id,
name: renamed.unwrap_or(item.ident).name, name: renamed.unwrap_or(item.ident).name,
kind: &item.kind, kind: &item.kind,
vis: &item.vis,
attrs: &item.attrs,
span: item.span,
}); });
} }
// Convert each `exported_macro` into a doc item. // Convert each `exported_macro` into a doc item.
fn visit_local_macro( fn visit_local_macro(&self, def: &'tcx hir::MacroDef<'_>, renamed: Option<Symbol>) -> Macro {
&self,
def: &'tcx hir::MacroDef<'_>,
renamed: Option<Symbol>,
) -> Macro<'tcx> {
debug!("visit_local_macro: {}", def.ident); debug!("visit_local_macro: {}", def.ident);
let tts = def.ast.body.inner_tokens().trees().collect::<Vec<_>>(); let tts = def.ast.body.inner_tokens().trees().collect::<Vec<_>>();
// Extract the spans of all matchers. They represent the "interface" of the macro. // Extract the spans of all matchers. They represent the "interface" of the macro.
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect(); let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect();
Macro { Macro {
hid: def.hir_id,
def_id: self.cx.tcx.hir().local_def_id(def.hir_id).to_def_id(), def_id: self.cx.tcx.hir().local_def_id(def.hir_id).to_def_id(),
attrs: &def.attrs,
name: renamed.unwrap_or(def.ident.name), name: renamed.unwrap_or(def.ident.name),
span: def.span,
matchers, matchers,
imported_from: None, imported_from: None,
} }