Skip to content

Commit

Permalink
Remove dead code in rustdoc::doctree
Browse files Browse the repository at this point in the history
It was completely unused.
  • Loading branch information
jyn514 committed Nov 14, 2020
1 parent 3f33f0c commit fff9203
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 139 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2304,7 +2304,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 {
Item::from_hir_id_and_parts(
self.id,
Expand Down
49 changes: 4 additions & 45 deletions src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,19 @@ pub struct Module<'hir> {
pub statics: Vec<Static<'hir>>,
pub constants: Vec<Constant<'hir>>,
pub traits: Vec<Trait<'hir>>,
pub vis: &'hir hir::Visibility<'hir>,
pub impls: Vec<Impl<'hir>>,
pub foreigns: Vec<ForeignItem<'hir>>,
pub macros: Vec<Macro<'hir>>,
pub proc_macros: Vec<ProcMacro<'hir>>,
pub proc_macros: Vec<ProcMacro>,
pub trait_aliases: Vec<TraitAlias<'hir>>,
pub is_crate: bool,
}

impl Module<'hir> {
pub fn new(
name: Option<Symbol>,
attrs: &'hir [ast::Attribute],
vis: &'hir hir::Visibility<'hir>,
) -> Module<'hir> {
pub fn new(name: Option<Symbol>, attrs: &'hir [ast::Attribute]) -> Module<'hir> {
Module {
name,
id: hir::CRATE_HIR_ID,
vis,
where_outer: rustc_span::DUMMY_SP,
where_inner: rustc_span::DUMMY_SP,
attrs,
Expand Down Expand Up @@ -83,53 +77,39 @@ pub enum StructType {
}

pub struct Struct<'hir> {
pub vis: &'hir hir::Visibility<'hir>,
pub id: hir::HirId,
pub struct_type: StructType,
pub name: Symbol,
pub generics: &'hir hir::Generics<'hir>,
pub attrs: &'hir [ast::Attribute],
pub fields: &'hir [hir::StructField<'hir>],
pub span: Span,
}

pub struct Union<'hir> {
pub vis: &'hir hir::Visibility<'hir>,
pub id: hir::HirId,
pub struct_type: StructType,
pub name: Symbol,
pub generics: &'hir hir::Generics<'hir>,
pub attrs: &'hir [ast::Attribute],
pub fields: &'hir [hir::StructField<'hir>],
pub span: Span,
}

pub struct Enum<'hir> {
pub vis: &'hir hir::Visibility<'hir>,
pub variants: Vec<Variant<'hir>>,
pub generics: &'hir hir::Generics<'hir>,
pub attrs: &'hir [ast::Attribute],
pub id: hir::HirId,
pub span: Span,
pub name: Symbol,
}

pub struct Variant<'hir> {
pub name: Symbol,
pub id: hir::HirId,
pub attrs: &'hir [ast::Attribute],
pub def: &'hir hir::VariantData<'hir>,
pub span: Span,
}

pub struct Function<'hir> {
pub decl: &'hir hir::FnDecl<'hir>,
pub attrs: &'hir [ast::Attribute],
pub id: hir::HirId,
pub name: Symbol,
pub vis: &'hir hir::Visibility<'hir>,
pub header: hir::FnHeader,
pub span: Span,
pub generics: &'hir hir::Generics<'hir>,
pub body: hir::BodyId,
}
Expand All @@ -139,18 +119,12 @@ pub struct Typedef<'hir> {
pub gen: &'hir hir::Generics<'hir>,
pub name: Symbol,
pub id: hir::HirId,
pub attrs: &'hir [ast::Attribute],
pub span: Span,
pub vis: &'hir hir::Visibility<'hir>,
}

pub struct OpaqueTy<'hir> {
pub opaque_ty: &'hir hir::OpaqueTy<'hir>,
pub name: Symbol,
pub id: hir::HirId,
pub attrs: &'hir [ast::Attribute],
pub span: Span,
pub vis: &'hir hir::Visibility<'hir>,
}

#[derive(Debug)]
Expand All @@ -169,10 +143,7 @@ pub struct Constant<'hir> {
pub type_: &'hir hir::Ty<'hir>,
pub expr: hir::BodyId,
pub name: Symbol,
pub attrs: &'hir [ast::Attribute],
pub vis: &'hir hir::Visibility<'hir>,
pub id: hir::HirId,
pub span: Span,
}

pub struct Trait<'hir> {
Expand All @@ -184,18 +155,13 @@ pub struct Trait<'hir> {
pub bounds: &'hir [hir::GenericBound<'hir>],
pub attrs: &'hir [ast::Attribute],
pub id: hir::HirId,
pub span: Span,
pub vis: &'hir hir::Visibility<'hir>,
}

pub struct TraitAlias<'hir> {
pub name: Symbol,
pub generics: &'hir hir::Generics<'hir>,
pub bounds: &'hir [hir::GenericBound<'hir>],
pub attrs: &'hir [ast::Attribute],
pub id: hir::HirId,
pub span: Span,
pub vis: &'hir hir::Visibility<'hir>,
}

#[derive(Debug)]
Expand All @@ -215,24 +181,19 @@ pub struct Impl<'hir> {
}

pub struct ForeignItem<'hir> {
pub vis: &'hir hir::Visibility<'hir>,
pub id: hir::HirId,
pub name: Symbol,
pub kind: &'hir hir::ForeignItemKind<'hir>,
pub attrs: &'hir [ast::Attribute],
pub span: Span,
}

// 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).
pub struct Macro<'hir> {
pub name: Symbol,
pub hid: hir::HirId,
pub def_id: hir::def_id::DefId,
pub attrs: &'hir [ast::Attribute],
pub span: Span,
pub matchers: Vec<Span>,
pub imported_from: Option<Symbol>,
pub attrs: &'hir [ast::Attribute],
}

pub struct ExternCrate<'hir> {
Expand All @@ -256,13 +217,11 @@ pub struct Import<'hir> {
pub span: Span,
}

pub struct ProcMacro<'hir> {
pub struct ProcMacro {
pub name: Symbol,
pub id: hir::HirId,
pub kind: MacroKind,
pub helpers: Vec<Symbol>,
pub attrs: &'hir [ast::Attribute],
pub span: Span,
}

pub fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
Expand Down
104 changes: 11 additions & 93 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
) -> Struct<'tcx> {
debug!("visiting struct");
let struct_type = struct_type_from_def(&*sd);
Struct {
id: item.hir_id,
struct_type,
name,
vis: &item.vis,
attrs: &item.attrs,
generics,
fields: sd.fields(),
span: item.span,
}
Struct { id: item.hir_id, struct_type, name, generics, fields: sd.fields() }
}

fn visit_union_data(
Expand All @@ -112,16 +103,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
) -> Union<'tcx> {
debug!("visiting union");
let struct_type = struct_type_from_def(&*sd);
Union {
id: item.hir_id,
struct_type,
name,
vis: &item.vis,
attrs: &item.attrs,
generics,
fields: sd.fields(),
span: item.span,
}
Union { id: item.hir_id, struct_type, name, generics, fields: sd.fields() }
}

fn visit_enum_def(
Expand All @@ -137,19 +119,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
variants: def
.variants
.iter()
.map(|v| Variant {
name: v.ident.name,
id: v.id,
attrs: &v.attrs,
def: &v.data,
span: v.span,
})
.map(|v| Variant { name: v.ident.name, id: v.id, def: &v.data })
.collect(),
vis: &it.vis,
generics,
attrs: &it.attrs,
id: it.hir_id,
span: it.span,
}
}

Expand Down Expand Up @@ -202,27 +175,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
}
}

om.proc_macros.push(ProcMacro {
name,
id: item.hir_id,
kind,
helpers,
attrs: &item.attrs,
span: item.span,
});
om.proc_macros.push(ProcMacro { name, id: item.hir_id, kind, helpers });
}
None => {
om.fns.push(Function {
id: item.hir_id,
vis: &item.vis,
attrs: &item.attrs,
decl,
name,
span: item.span,
generics,
header,
body,
});
om.fns.push(Function { id: item.hir_id, decl, name, generics, header, body });
}
}
}
Expand All @@ -236,7 +192,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
m: &'tcx hir::Mod<'tcx>,
name: Option<Symbol>,
) -> Module<'tcx> {
let mut om = Module::new(name, attrs, vis);
let mut om = Module::new(name, attrs);
om.where_outer = span;
om.where_inner = m.inner;
om.id = id;
Expand Down Expand Up @@ -471,26 +427,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
self.visit_fn(om, item, ident.name, &sig.decl, sig.header, gen, body)
}
hir::ItemKind::TyAlias(ty, ref gen) => {
let t = Typedef {
ty,
gen,
name: ident.name,
id: item.hir_id,
attrs: &item.attrs,
span: item.span,
vis: &item.vis,
};
let t = Typedef { ty, gen, name: ident.name, id: item.hir_id };
om.typedefs.push(t);
}
hir::ItemKind::OpaqueTy(ref opaque_ty) => {
let t = OpaqueTy {
opaque_ty,
name: ident.name,
id: item.hir_id,
attrs: &item.attrs,
span: item.span,
vis: &item.vis,
};
let t = OpaqueTy { opaque_ty, name: ident.name, id: item.hir_id };
om.opaque_tys.push(t);
}
hir::ItemKind::Static(type_, mutability, expr) => {
Expand All @@ -510,15 +451,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// Underscore constants do not correspond to a nameable item and
// so are never useful in documentation.
if ident.name != kw::Underscore {
let s = Constant {
type_,
expr,
id: item.hir_id,
name: ident.name,
attrs: &item.attrs,
span: item.span,
vis: &item.vis,
};
let s = Constant { type_, expr, id: item.hir_id, name: ident.name };
om.constants.push(s);
}
}
Expand All @@ -533,21 +466,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
bounds,
id: item.hir_id,
attrs: &item.attrs,
span: item.span,
vis: &item.vis,
};
om.traits.push(t);
}
hir::ItemKind::TraitAlias(ref generics, ref bounds) => {
let t = TraitAlias {
name: ident.name,
generics,
bounds,
id: item.hir_id,
attrs: &item.attrs,
span: item.span,
vis: &item.vis,
};
let t = TraitAlias { name: ident.name, generics, bounds, id: item.hir_id };
om.trait_aliases.push(t);
}

Expand Down Expand Up @@ -602,9 +525,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
id: item.hir_id,
name: renamed.unwrap_or(item.ident).name,
kind: &item.kind,
vis: &item.vis,
attrs: &item.attrs,
span: item.span,
});
}

Expand All @@ -620,13 +540,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect();

Macro {
hid: def.hir_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),
span: def.span,
matchers,
imported_from: None,
attrs: def.attrs,
}
}
}

0 comments on commit fff9203

Please sign in to comment.