From e62f6a0e872d6016320586195f06447408fb15e1 Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 11 Jul 2022 00:08:55 +0200 Subject: [PATCH 1/6] Remove box syntax from Box construction The type has 240 bytes according to compiler internal rustdoc. --- src/librustdoc/clean/inline.rs | 4 ++-- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/clean/types.rs | 2 +- src/librustdoc/fold.rs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 731d8766686c8..d5dd040eceda4 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -538,7 +538,7 @@ fn build_module( attrs: Box::new(clean::Attributes::default()), item_id: ItemId::Primitive(prim_ty, did.krate), visibility: clean::Public, - kind: box clean::ImportItem(clean::Import::new_simple( + kind: Box::new(clean::ImportItem(clean::Import::new_simple( item.ident.name, clean::ImportSource { path: clean::Path { @@ -554,7 +554,7 @@ fn build_module( did: None, }, true, - )), + ))), cfg: None, }); } else if let Some(i) = try_inline(cx, did, None, res, item.ident.name, None, visited) { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 624eec57e8324..f4d66907b7ae2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2108,7 +2108,7 @@ fn clean_extern_crate<'tcx>( attrs: Box::new(attrs.clean(cx)), item_id: crate_def_id.into(), visibility: clean_visibility(ty_vis), - kind: box ExternCrateItem { src: orig_name }, + kind: Box::new(ExternCrateItem { src: orig_name }), cfg: attrs.cfg(cx.tcx, &cx.cache.hidden_cfg), }] } diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index a5d27a940341a..09438c40dc1d7 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -502,7 +502,7 @@ impl Item { clean_visibility(cx.tcx.visibility(def_id)) }; - Item { item_id: def_id.into(), kind: box kind, name, attrs, visibility, cfg } + Item { item_id: def_id.into(), kind: Box::new(kind), name, attrs, visibility, cfg } } /// Finds all `doc` attributes as NameValues and returns their corresponding values, joined diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index c93897236db69..6b7e67e2ce342 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -2,7 +2,7 @@ use crate::clean::*; pub(crate) fn strip_item(mut item: Item) -> Item { if !matches!(*item.kind, StrippedItem(..)) { - item.kind = box StrippedItem(item.kind); + item.kind = Box::new(StrippedItem(item.kind)); } item } @@ -75,10 +75,10 @@ pub(crate) trait DocFolder: Sized { /// don't override! fn fold_item_recur(&mut self, mut item: Item) -> Item { - item.kind = box match *item.kind { - StrippedItem(box i) => StrippedItem(box self.fold_inner_recur(i)), + item.kind = Box::new(match *item.kind { + StrippedItem(box i) => StrippedItem(Box::new(self.fold_inner_recur(i))), _ => self.fold_inner_recur(*item.kind), - }; + }); item } From 79246e8e9a4cac5dc4330da4af4342f3d95b688d Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 21 Jul 2022 23:00:28 +0200 Subject: [PATCH 2/6] Remove box syntax from doctest.rs --- src/librustdoc/doctest.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 568bad2a382c1..213f564ce2db5 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -740,7 +740,7 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool { rustc_errors::fallback_fluent_bundle(rustc_errors::DEFAULT_LOCALE_RESOURCES, false); let emitter = EmitterWriter::new( - box io::sink(), + Box::new(io::sink()), None, None, fallback_bundle, @@ -751,7 +751,7 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool { false, ); - let handler = Handler::with_emitter(false, None, box emitter); + let handler = Handler::with_emitter(false, None, Box::new(emitter)); let sess = ParseSess::with_span_handler(handler, sm); let mut parser = match maybe_new_parser_from_source_str(&sess, filename, source.to_owned()) { From 0bf65c7c9275e99084359bc4ace82f21d5d89bff Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 11 Jul 2022 00:29:15 +0200 Subject: [PATCH 3/6] Remove box_syntax feature gate from librustdoc --- src/librustdoc/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 3a96884d45d9f..0fe720e70cf0f 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -7,7 +7,6 @@ #![feature(assert_matches)] #![feature(box_patterns)] #![feature(control_flow_enum)] -#![feature(box_syntax)] #![feature(drain_filter)] #![cfg_attr(bootstrap, feature(let_chains))] #![feature(let_else)] From 96c051fd0743e52403f0c3dcdbdbb8297da4ac99 Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 21 Jul 2022 23:14:12 +0200 Subject: [PATCH 4/6] Box TypedefItem, ImplItem, AssocTypeItem variants of ItemKind This reduces ItemKind size from 224 bytes to 160 bytes. --- src/librustdoc/clean/auto_trait.rs | 4 ++-- src/librustdoc/clean/blanket_impl.rs | 4 ++-- src/librustdoc/clean/inline.rs | 10 ++++----- src/librustdoc/clean/mod.rs | 22 +++++++++---------- src/librustdoc/clean/types.rs | 10 ++++----- src/librustdoc/formats/cache.rs | 2 +- src/librustdoc/html/render/mod.rs | 4 ++-- src/librustdoc/json/conversions.rs | 12 +++++----- .../passes/check_doc_test_visibility.rs | 2 +- src/librustdoc/passes/collect_trait_impls.rs | 4 ++-- 10 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index c43fd1ad24173..5fe2c9ab4e37b 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -117,7 +117,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { attrs: Default::default(), visibility: Inherited, item_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id }, - kind: Box::new(ImplItem(Impl { + kind: Box::new(ImplItem(Box::new(Impl { unsafety: hir::Unsafety::Normal, generics: new_generics, trait_: Some(trait_ref.clean(self.cx)), @@ -125,7 +125,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { items: Vec::new(), polarity, kind: ImplKind::Auto, - })), + }))), cfg: None, }) } diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index c64c5895079be..8aecd9b15e842 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -106,7 +106,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { attrs: Default::default(), visibility: Inherited, item_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id }, - kind: Box::new(ImplItem(Impl { + kind: Box::new(ImplItem(Box::new(Impl { unsafety: hir::Unsafety::Normal, generics: clean_ty_generics( cx, @@ -124,7 +124,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { .collect::>(), polarity: ty::ImplPolarity::Positive, kind: ImplKind::Blanket(Box::new(clean_middle_ty(trait_ref.0.self_ty(), cx, None))), - })), + }))), cfg: None, }); } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index d5dd040eceda4..6547c89440795 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -260,15 +260,15 @@ fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union { clean::Union { generics, fields } } -fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::Typedef { +fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> Box { let predicates = cx.tcx.explicit_predicates_of(did); let type_ = clean_middle_ty(cx.tcx.type_of(did), cx, Some(did)); - clean::Typedef { + Box::new(clean::Typedef { type_, generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates), item_type: None, - } + }) } /// Builds all inherent implementations of an ADT (struct/union/enum) or Trait item/path/reexport. @@ -493,7 +493,7 @@ pub(crate) fn build_impl( ret.push(clean::Item::from_def_id_and_attrs_and_parts( did, None, - clean::ImplItem(clean::Impl { + clean::ImplItem(Box::new(clean::Impl { unsafety: hir::Unsafety::Normal, generics, trait_, @@ -505,7 +505,7 @@ pub(crate) fn build_impl( } else { ImplKind::Normal }, - }), + })), Box::new(merged_attrs), cx, cfg, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f4d66907b7ae2..a216849083c8e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1068,11 +1068,11 @@ impl<'tcx> Clean<'tcx, Item> for hir::TraitItem<'tcx> { let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect(); let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, default), cx, None); AssocTypeItem( - Typedef { + Box::new(Typedef { type_: clean_ty(default, cx), generics, item_type: Some(item_type), - }, + }), bounds, ) } @@ -1109,7 +1109,7 @@ impl<'tcx> Clean<'tcx, Item> for hir::ImplItem<'tcx> { let generics = self.generics.clean(cx); let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, hir_ty), cx, None); AssocTypeItem( - Typedef { type_, generics, item_type: Some(item_type) }, + Box::new(Typedef { type_, generics, item_type: Some(item_type) }), Vec::new(), ) } @@ -1282,7 +1282,7 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem { if self.defaultness.has_value() { AssocTypeItem( - Typedef { + Box::new(Typedef { type_: clean_middle_ty( tcx.type_of(self.def_id), cx, @@ -1291,7 +1291,7 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem { generics, // FIXME: should we obtain the Type from HIR and pass it on here? item_type: None, - }, + }), bounds, ) } else { @@ -1300,11 +1300,11 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem { } else { // FIXME: when could this happen? Associated items in inherent impls? AssocTypeItem( - Typedef { + Box::new(Typedef { type_: clean_middle_ty(tcx.type_of(self.def_id), cx, Some(self.def_id)), generics: Generics { params: Vec::new(), where_predicates: Vec::new() }, item_type: None, - }, + }), Vec::new(), ) } @@ -1949,11 +1949,11 @@ fn clean_maybe_renamed_item<'tcx>( ItemKind::TyAlias(hir_ty, generics) => { let rustdoc_ty = clean_ty(hir_ty, cx); let ty = clean_middle_ty(hir_ty_to_ty(cx.tcx, hir_ty), cx, None); - TypedefItem(Typedef { + TypedefItem(Box::new(Typedef { type_: rustdoc_ty, generics: generics.clean(cx), item_type: Some(ty), - }) + })) } ItemKind::Enum(ref def, generics) => EnumItem(Enum { variants: def.variants.iter().map(|v| v.clean(cx)).collect(), @@ -2041,7 +2041,7 @@ fn clean_impl<'tcx>( _ => None, }); let mut make_item = |trait_: Option, for_: Type, items: Vec| { - let kind = ImplItem(Impl { + let kind = ImplItem(Box::new(Impl { unsafety: impl_.unsafety, generics: impl_.generics.clean(cx), trait_, @@ -2053,7 +2053,7 @@ fn clean_impl<'tcx>( } else { ImplKind::Normal }, - }); + })); Item::from_hir_id_and_parts(hir_id, None, kind, cx) }; if let Some(type_alias) = type_alias { diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 09438c40dc1d7..ced570c7f9326 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -430,8 +430,8 @@ impl Item { }; match kind { ItemKind::ModuleItem(Module { span, .. }) => *span, - ItemKind::ImplItem(Impl { kind: ImplKind::Auto, .. }) => Span::dummy(), - ItemKind::ImplItem(Impl { kind: ImplKind::Blanket(_), .. }) => { + ItemKind::ImplItem(box Impl { kind: ImplKind::Auto, .. }) => Span::dummy(), + ItemKind::ImplItem(box Impl { kind: ImplKind::Blanket(_), .. }) => { if let ItemId::Blanket { impl_id, .. } = self.item_id { rustc_span(impl_id, tcx) } else { @@ -732,13 +732,13 @@ pub(crate) enum ItemKind { EnumItem(Enum), FunctionItem(Function), ModuleItem(Module), - TypedefItem(Typedef), + TypedefItem(Box), OpaqueTyItem(OpaqueTy), StaticItem(Static), ConstantItem(Constant), TraitItem(Trait), TraitAliasItem(TraitAlias), - ImplItem(Impl), + ImplItem(Box), /// A required method in a trait declaration meaning it's only a function signature. TyMethodItem(Function), /// A method in a trait impl or a provided method in a trait declaration. @@ -765,7 +765,7 @@ pub(crate) enum ItemKind { /// The bounds may be non-empty if there is a `where` clause. TyAssocTypeItem(Box, Vec), /// An associated type in a trait impl or a provided one in a trait declaration. - AssocTypeItem(Typedef, Vec), + AssocTypeItem(Box, Vec), /// An item that has been stripped by a rustdoc pass StrippedItem(Box), KeywordItem, diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index b9774eb70ea02..2b2691e53bbcc 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -536,7 +536,7 @@ enum ParentStackItem { impl ParentStackItem { fn new(item: &clean::Item) -> Self { match &*item.kind { - clean::ItemKind::ImplItem(clean::Impl { for_, trait_, generics, kind, .. }) => { + clean::ItemKind::ImplItem(box clean::Impl { for_, trait_, generics, kind, .. }) => { ParentStackItem::Impl { for_: for_.clone(), trait_: trait_.clone(), diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 89d372da32278..a262c8f7d1948 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1160,7 +1160,7 @@ fn render_deref_methods( .items .iter() .find_map(|item| match *item.kind { - clean::AssocTypeItem(ref t, _) => Some(match *t { + clean::AssocTypeItem(box ref t, _) => Some(match *t { clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_), _ => (&t.type_, &t.type_), }), @@ -2054,7 +2054,7 @@ fn sidebar_deref_methods( debug!("found Deref: {:?}", impl_); if let Some((target, real_target)) = impl_.inner_impl().items.iter().find_map(|item| match *item.kind { - clean::AssocTypeItem(ref t, _) => Some(match *t { + clean::AssocTypeItem(box ref t, _) => Some(match *t { clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_), _ => (&t.type_, &t.type_), }), diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 5f3dd57061051..b6ee385a833cb 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -568,10 +568,10 @@ impl FromWithTcx for Trait { } } -impl FromWithTcx for Impl { - fn from_tcx(impl_: clean::Impl, tcx: TyCtxt<'_>) -> Self { +impl FromWithTcx> for Impl { + fn from_tcx(impl_: Box, tcx: TyCtxt<'_>) -> Self { let provided_trait_methods = impl_.provided_trait_methods(tcx); - let clean::Impl { unsafety, generics, trait_, for_, items, polarity, kind } = impl_; + let clean::Impl { unsafety, generics, trait_, for_, items, polarity, kind } = *impl_; // FIXME: should `trait_` be a clean::Path equivalent in JSON? let trait_ = trait_.map(|path| clean::Type::Path { path }.into_tcx(tcx)); // FIXME: use something like ImplKind in JSON? @@ -721,9 +721,9 @@ pub(crate) fn from_macro_kind(kind: rustc_span::hygiene::MacroKind) -> MacroKind } } -impl FromWithTcx for Typedef { - fn from_tcx(typedef: clean::Typedef, tcx: TyCtxt<'_>) -> Self { - let clean::Typedef { type_, generics, item_type: _ } = typedef; +impl FromWithTcx> for Typedef { + fn from_tcx(typedef: Box, tcx: TyCtxt<'_>) -> Self { + let clean::Typedef { type_, generics, item_type: _ } = *typedef; Typedef { type_: type_.into_tcx(tcx), generics: generics.into_tcx(tcx) } } } diff --git a/src/librustdoc/passes/check_doc_test_visibility.rs b/src/librustdoc/passes/check_doc_test_visibility.rs index e80a94fe749de..e86f9083394cf 100644 --- a/src/librustdoc/passes/check_doc_test_visibility.rs +++ b/src/librustdoc/passes/check_doc_test_visibility.rs @@ -71,7 +71,7 @@ pub(crate) fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) - | clean::PrimitiveItem(_) | clean::KeywordItem // check for trait impl - | clean::ImplItem(clean::Impl { trait_: Some(_), .. }) + | clean::ImplItem(box clean::Impl { trait_: Some(_), .. }) ) { return false; diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 6ea33d763b185..6b699c7901434 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -146,7 +146,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> // scan through included items ahead of time to splice in Deref targets to the "valid" sets for it in new_items_external.iter().chain(new_items_local.iter()) { - if let ImplItem(Impl { ref for_, ref trait_, ref items, .. }) = *it.kind { + if let ImplItem(box Impl { ref for_, ref trait_, ref items, .. }) = *it.kind { if trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait() && cleaner.keep_impl(for_, true) { @@ -187,7 +187,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> // Filter out external items that are not needed new_items_external.retain(|it| { - if let ImplItem(Impl { ref for_, ref trait_, ref kind, .. }) = *it.kind { + if let ImplItem(box Impl { ref for_, ref trait_, ref kind, .. }) = *it.kind { cleaner.keep_impl( for_, trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait(), From 1116fc164f1fce1cab2753fab294bfe016457a69 Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 22 Jul 2022 00:11:21 +0200 Subject: [PATCH 5/6] Box FunctionItem, TyMethodItem, MethodItem, ForeignFunctionItem This reduces ItemKind size from 160 bytes to 112 bytes --- src/librustdoc/clean/inline.rs | 4 ++-- src/librustdoc/clean/mod.rs | 12 ++++++------ src/librustdoc/clean/types.rs | 8 ++++---- src/librustdoc/json/conversions.rs | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 6547c89440795..55d77a63f6141 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -218,7 +218,7 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds } } -fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> clean::Function { +fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> Box { let sig = cx.tcx.fn_sig(did); let predicates = cx.tcx.predicates_of(did); @@ -228,7 +228,7 @@ fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> clean let decl = clean_fn_decl_from_did_and_sig(cx, Some(did), sig); (generics, decl) }); - clean::Function { decl, generics } + Box::new(clean::Function { decl, generics }) } fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index a216849083c8e..10676aca480dd 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -908,7 +908,7 @@ fn clean_function<'tcx>( sig: &hir::FnSig<'tcx>, generics: &hir::Generics<'tcx>, body_id: hir::BodyId, -) -> Function { +) -> Box { let (generics, decl) = enter_impl_trait(cx, |cx| { // NOTE: generics must be cleaned before args let generics = generics.clean(cx); @@ -916,7 +916,7 @@ fn clean_function<'tcx>( let decl = clean_fn_decl_with_args(cx, sig.decl, args); (generics, decl) }); - Function { decl, generics } + Box::new(Function { decl, generics }) } fn clean_args_from_types_and_names<'tcx>( @@ -1061,7 +1061,7 @@ impl<'tcx> Clean<'tcx, Item> for hir::TraitItem<'tcx> { let decl = clean_fn_decl_with_args(cx, sig.decl, args); (generics, decl) }); - TyMethodItem(Function { decl, generics }) + TyMethodItem(Box::new(Function { decl, generics })) } hir::TraitItemKind::Type(bounds, Some(default)) => { let generics = enter_impl_trait(cx, |cx| self.generics.clean(cx)); @@ -1186,9 +1186,9 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem { ty::ImplContainer(_) => Some(self.defaultness), ty::TraitContainer(_) => None, }; - MethodItem(Function { generics, decl }, defaultness) + MethodItem(Box::new(Function { generics, decl }), defaultness) } else { - TyMethodItem(Function { generics, decl }) + TyMethodItem(Box::new(Function { generics, decl })) } } ty::AssocKind::Type => { @@ -2243,7 +2243,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>( let decl = clean_fn_decl_with_args(cx, decl, args); (generics, decl) }); - ForeignFunctionItem(Function { decl, generics }) + ForeignFunctionItem(Box::new(Function { decl, generics })) } hir::ForeignItemKind::Static(ty, mutability) => { ForeignStaticItem(Static { type_: clean_ty(ty, cx), mutability, expr: None }) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index ced570c7f9326..874cf5508d174 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -730,7 +730,7 @@ pub(crate) enum ItemKind { StructItem(Struct), UnionItem(Union), EnumItem(Enum), - FunctionItem(Function), + FunctionItem(Box), ModuleItem(Module), TypedefItem(Box), OpaqueTyItem(OpaqueTy), @@ -740,15 +740,15 @@ pub(crate) enum ItemKind { TraitAliasItem(TraitAlias), ImplItem(Box), /// A required method in a trait declaration meaning it's only a function signature. - TyMethodItem(Function), + TyMethodItem(Box), /// A method in a trait impl or a provided method in a trait declaration. /// /// Compared to [TyMethodItem], it also contains a method body. - MethodItem(Function, Option), + MethodItem(Box, Option), StructFieldItem(Type), VariantItem(Variant), /// `fn`s from an extern block - ForeignFunctionItem(Function), + ForeignFunctionItem(Box), /// `static`s from an extern block ForeignStaticItem(Static), /// `type`s from an extern block diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index b6ee385a833cb..716a4c9ea4319 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -602,11 +602,11 @@ impl FromWithTcx> for Impl { } pub(crate) fn from_function( - function: clean::Function, + function: Box, header: rustc_hir::FnHeader, tcx: TyCtxt<'_>, ) -> Function { - let clean::Function { decl, generics } = function; + let clean::Function { decl, generics } = *function; Function { decl: decl.into_tcx(tcx), generics: generics.into_tcx(tcx), @@ -615,12 +615,12 @@ pub(crate) fn from_function( } pub(crate) fn from_function_method( - function: clean::Function, + function: Box, has_body: bool, header: rustc_hir::FnHeader, tcx: TyCtxt<'_>, ) -> Method { - let clean::Function { decl, generics } = function; + let clean::Function { decl, generics } = *function; Method { decl: decl.into_tcx(tcx), generics: generics.into_tcx(tcx), From fabb4b0661c1ece43d7e0011c88f9ae225691608 Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 21 Jul 2022 23:54:16 +0200 Subject: [PATCH 6/6] Statically ensure the size of ItemKind --- src/librustdoc/clean/types.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 874cf5508d174..d022ce9696ad0 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -771,6 +771,10 @@ pub(crate) enum ItemKind { KeywordItem, } +// `ItemKind` is an enum and large variants can bloat up memory usage even for smaller ones +#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] +rustc_data_structures::static_assert_size!(ItemKind, 112); + impl ItemKind { /// Some items contain others such as structs (for their fields) and Enums /// (for their variants). This method returns those contained items.