diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e58e4c3cdb1d6..73a6c76f4c558 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2304,7 +2304,7 @@ impl Clean for doctree::Macro<'_> { } } -impl Clean for doctree::ProcMacro<'_> { +impl Clean for doctree::ProcMacro { fn clean(&self, cx: &DocContext<'_>) -> Item { Item::from_hir_id_and_parts( self.id, diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index ee217d99d2c77..406edac4d212a 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -28,25 +28,19 @@ pub struct Module<'hir> { pub statics: Vec>, pub constants: Vec>, pub traits: Vec>, - pub vis: &'hir hir::Visibility<'hir>, pub impls: Vec>, pub foreigns: Vec>, pub macros: Vec>, - pub proc_macros: Vec>, + pub proc_macros: Vec, pub trait_aliases: Vec>, pub is_crate: bool, } impl Module<'hir> { - pub fn new( - name: Option, - attrs: &'hir [ast::Attribute], - vis: &'hir hir::Visibility<'hir>, - ) -> Module<'hir> { + pub fn new(name: Option, 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 @@ 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>, 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, } @@ -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)] @@ -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> { @@ -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)] @@ -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, pub imported_from: Option, + pub attrs: &'hir [ast::Attribute], } pub struct ExternCrate<'hir> { @@ -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, - pub attrs: &'hir [ast::Attribute], - pub span: Span, } pub fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index cbfd2199d9fd6..8c4215f07c842 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -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, ) -> 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,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, }); } @@ -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, } } }