mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Remove dead code in rustdoc::doctree
It was completely unused.
This commit is contained in:
parent
fc4ca55291
commit
0e1a302f59
@ -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 {
|
||||
Item::from_def_id_and_parts(
|
||||
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 {
|
||||
Item::from_hir_id_and_parts(
|
||||
self.id,
|
||||
|
@ -28,25 +28,19 @@ crate struct Module<'hir> {
|
||||
crate statics: Vec<Static<'hir>>,
|
||||
crate constants: Vec<Constant<'hir>>,
|
||||
crate traits: Vec<Trait<'hir>>,
|
||||
crate vis: &'hir hir::Visibility<'hir>,
|
||||
crate impls: Vec<Impl<'hir>>,
|
||||
crate foreigns: Vec<ForeignItem<'hir>>,
|
||||
crate macros: Vec<Macro<'hir>>,
|
||||
crate proc_macros: Vec<ProcMacro<'hir>>,
|
||||
crate macros: Vec<Macro>,
|
||||
crate proc_macros: Vec<ProcMacro>,
|
||||
crate trait_aliases: Vec<TraitAlias<'hir>>,
|
||||
crate is_crate: bool,
|
||||
}
|
||||
|
||||
impl Module<'hir> {
|
||||
crate fn new(
|
||||
name: Option<Symbol>,
|
||||
attrs: &'hir [ast::Attribute],
|
||||
vis: &'hir hir::Visibility<'hir>,
|
||||
) -> Module<'hir> {
|
||||
crate 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,
|
||||
@ -83,53 +77,39 @@ crate enum StructType {
|
||||
}
|
||||
|
||||
crate struct Struct<'hir> {
|
||||
crate vis: &'hir hir::Visibility<'hir>,
|
||||
crate id: hir::HirId,
|
||||
crate struct_type: StructType,
|
||||
crate name: Symbol,
|
||||
crate generics: &'hir hir::Generics<'hir>,
|
||||
crate attrs: &'hir [ast::Attribute],
|
||||
crate fields: &'hir [hir::StructField<'hir>],
|
||||
crate span: Span,
|
||||
}
|
||||
|
||||
crate struct Union<'hir> {
|
||||
crate vis: &'hir hir::Visibility<'hir>,
|
||||
crate id: hir::HirId,
|
||||
crate struct_type: StructType,
|
||||
crate name: Symbol,
|
||||
crate generics: &'hir hir::Generics<'hir>,
|
||||
crate attrs: &'hir [ast::Attribute],
|
||||
crate fields: &'hir [hir::StructField<'hir>],
|
||||
crate span: Span,
|
||||
}
|
||||
|
||||
crate struct Enum<'hir> {
|
||||
crate vis: &'hir hir::Visibility<'hir>,
|
||||
crate variants: Vec<Variant<'hir>>,
|
||||
crate generics: &'hir hir::Generics<'hir>,
|
||||
crate attrs: &'hir [ast::Attribute],
|
||||
crate id: hir::HirId,
|
||||
crate span: Span,
|
||||
crate name: Symbol,
|
||||
}
|
||||
|
||||
crate struct Variant<'hir> {
|
||||
crate name: Symbol,
|
||||
crate id: hir::HirId,
|
||||
crate attrs: &'hir [ast::Attribute],
|
||||
crate def: &'hir hir::VariantData<'hir>,
|
||||
crate span: Span,
|
||||
}
|
||||
|
||||
crate struct Function<'hir> {
|
||||
crate decl: &'hir hir::FnDecl<'hir>,
|
||||
crate attrs: &'hir [ast::Attribute],
|
||||
crate id: hir::HirId,
|
||||
crate name: Symbol,
|
||||
crate vis: &'hir hir::Visibility<'hir>,
|
||||
crate header: hir::FnHeader,
|
||||
crate span: Span,
|
||||
crate generics: &'hir hir::Generics<'hir>,
|
||||
crate body: hir::BodyId,
|
||||
}
|
||||
@ -139,18 +119,12 @@ crate struct Typedef<'hir> {
|
||||
crate gen: &'hir hir::Generics<'hir>,
|
||||
crate name: Symbol,
|
||||
crate id: hir::HirId,
|
||||
crate attrs: &'hir [ast::Attribute],
|
||||
crate span: Span,
|
||||
crate vis: &'hir hir::Visibility<'hir>,
|
||||
}
|
||||
|
||||
crate struct OpaqueTy<'hir> {
|
||||
crate opaque_ty: &'hir hir::OpaqueTy<'hir>,
|
||||
crate name: Symbol,
|
||||
crate id: hir::HirId,
|
||||
crate attrs: &'hir [ast::Attribute],
|
||||
crate span: Span,
|
||||
crate vis: &'hir hir::Visibility<'hir>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -169,10 +143,7 @@ crate struct Constant<'hir> {
|
||||
crate type_: &'hir hir::Ty<'hir>,
|
||||
crate expr: hir::BodyId,
|
||||
crate name: Symbol,
|
||||
crate attrs: &'hir [ast::Attribute],
|
||||
crate vis: &'hir hir::Visibility<'hir>,
|
||||
crate id: hir::HirId,
|
||||
crate span: Span,
|
||||
}
|
||||
|
||||
crate struct Trait<'hir> {
|
||||
@ -184,18 +155,13 @@ crate struct Trait<'hir> {
|
||||
crate bounds: &'hir [hir::GenericBound<'hir>],
|
||||
crate attrs: &'hir [ast::Attribute],
|
||||
crate id: hir::HirId,
|
||||
crate span: Span,
|
||||
crate vis: &'hir hir::Visibility<'hir>,
|
||||
}
|
||||
|
||||
crate struct TraitAlias<'hir> {
|
||||
crate name: Symbol,
|
||||
crate generics: &'hir hir::Generics<'hir>,
|
||||
crate bounds: &'hir [hir::GenericBound<'hir>],
|
||||
crate attrs: &'hir [ast::Attribute],
|
||||
crate id: hir::HirId,
|
||||
crate span: Span,
|
||||
crate vis: &'hir hir::Visibility<'hir>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -215,22 +181,16 @@ crate struct Impl<'hir> {
|
||||
}
|
||||
|
||||
crate struct ForeignItem<'hir> {
|
||||
crate vis: &'hir hir::Visibility<'hir>,
|
||||
crate id: hir::HirId,
|
||||
crate name: Symbol,
|
||||
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
|
||||
// these imported macro_rules (which only have a DUMMY_NODE_ID).
|
||||
crate struct Macro<'hir> {
|
||||
crate struct Macro {
|
||||
crate name: Symbol,
|
||||
crate hid: hir::HirId,
|
||||
crate def_id: hir::def_id::DefId,
|
||||
crate attrs: &'hir [ast::Attribute],
|
||||
crate span: Span,
|
||||
crate matchers: Vec<Span>,
|
||||
crate imported_from: Option<Symbol>,
|
||||
}
|
||||
@ -256,13 +216,11 @@ crate struct Import<'hir> {
|
||||
crate span: Span,
|
||||
}
|
||||
|
||||
crate struct ProcMacro<'hir> {
|
||||
crate struct ProcMacro {
|
||||
crate name: Symbol,
|
||||
crate id: hir::HirId,
|
||||
crate kind: MacroKind,
|
||||
crate helpers: Vec<Symbol>,
|
||||
crate attrs: &'hir [ast::Attribute],
|
||||
crate span: Span,
|
||||
}
|
||||
|
||||
crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
|
||||
|
@ -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(
|
||||
@ -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(
|
||||
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
@ -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) => {
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -602,29 +525,19 @@ 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,
|
||||
});
|
||||
}
|
||||
|
||||
// Convert each `exported_macro` into a doc item.
|
||||
fn visit_local_macro(
|
||||
&self,
|
||||
def: &'tcx hir::MacroDef<'_>,
|
||||
renamed: Option<Symbol>,
|
||||
) -> Macro<'tcx> {
|
||||
fn visit_local_macro(&self, def: &'tcx hir::MacroDef<'_>, renamed: Option<Symbol>) -> Macro {
|
||||
debug!("visit_local_macro: {}", def.ident);
|
||||
let tts = def.ast.body.inner_tokens().trees().collect::<Vec<_>>();
|
||||
// Extract the spans of all matchers. They represent the "interface" of the macro.
|
||||
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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user