diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 7a61a169c2bd2..d01677acdd62b 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -126,7 +126,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { stability: None, const_stability: None, deprecation: None, - kind: ImplItem(Impl { + kind: ImplItem(box Impl { unsafety: hir::Unsafety::Normal, generics: new_generics, provided_trait_methods: Default::default(), diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 33b5e84c5e074..e41ed79a0cf87 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -115,7 +115,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { stability: None, const_stability: None, deprecation: None, - kind: ImplItem(Impl { + kind: ImplItem(box Impl { unsafety: hir::Unsafety::Normal, generics: ( self.cx.tcx.generics_of(impl_def_id), diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index f7b6553a9359a..a8d5fff83d44c 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -62,7 +62,7 @@ crate fn try_inline( } Res::Def(DefKind::Fn, did) => { record_extern_fqn(cx, did, clean::TypeKind::Function); - clean::FunctionItem(build_external_function(cx, did)) + clean::FunctionItem(box build_external_function(cx, did)) } Res::Def(DefKind::Struct, did) => { record_extern_fqn(cx, did, clean::TypeKind::Struct); @@ -77,7 +77,7 @@ crate fn try_inline( Res::Def(DefKind::TyAlias, did) => { record_extern_fqn(cx, did, clean::TypeKind::Typedef); ret.extend(build_impls(cx, Some(parent_module), did, attrs)); - clean::TypedefItem(build_type_alias(cx, did), false) + clean::TypedefItem(box build_type_alias(cx, did), false) } Res::Def(DefKind::Enum, did) => { record_extern_fqn(cx, did, clean::TypeKind::Enum); @@ -435,7 +435,7 @@ crate fn build_impl( let mut item = clean::Item::from_def_id_and_parts( did, None, - clean::ImplItem(clean::Impl { + clean::ImplItem(box clean::Impl { unsafety: hir::Unsafety::Normal, generics, provided_trait_methods: provided, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 1a63a5092ca07..f49ae9030141e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -919,7 +919,7 @@ fn clean_fn_or_proc_macro( } else { hir::Constness::NotConst }; - FunctionItem(func) + FunctionItem(box func) } } } @@ -1076,7 +1076,7 @@ impl Clean for hir::TraitItem<'_> { { m.header.constness = hir::Constness::NotConst; } - MethodItem(m, None) + MethodItem(box m, None) } hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(ref names)) => { let (generics, decl) = enter_impl_trait(cx, || { @@ -1090,7 +1090,7 @@ impl Clean for hir::TraitItem<'_> { { t.header.constness = hir::Constness::NotConst; } - TyMethodItem(t) + TyMethodItem(box t) } hir::TraitItemKind::Type(ref bounds, ref default) => { AssocTypeItem(bounds.clean(cx), default.clean(cx)) @@ -1116,12 +1116,12 @@ impl Clean for hir::ImplItem<'_> { { m.header.constness = hir::Constness::NotConst; } - MethodItem(m, Some(self.defaultness)) + MethodItem(box m, Some(self.defaultness)) } hir::ImplItemKind::TyAlias(ref ty) => { let type_ = ty.clean(cx); let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did)); - TypedefItem(Typedef { type_, generics: Generics::default(), item_type }, true) + TypedefItem(box Typedef { type_, generics: Generics::default(), item_type }, true) } }; Item::from_def_id_and_parts(local_did, Some(self.ident.name.clean(cx)), inner, cx) @@ -1185,7 +1185,7 @@ impl Clean for ty::AssocItem { ty::TraitContainer(_) => None, }; MethodItem( - Function { + box Function { generics, decl, header: hir::FnHeader { @@ -1200,7 +1200,7 @@ impl Clean for ty::AssocItem { defaultness, ) } else { - TyMethodItem(Function { + TyMethodItem(box Function { generics, decl, header: hir::FnHeader { @@ -1270,7 +1270,7 @@ impl Clean for ty::AssocItem { let type_ = cx.tcx.type_of(self.def_id).clean(cx); let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did)); TypedefItem( - Typedef { + box Typedef { type_, generics: Generics { params: Vec::new(), where_predicates: Vec::new() }, item_type, @@ -1981,7 +1981,7 @@ impl Clean> for (&hir::Item<'_>, Option) { let rustdoc_ty = ty.clean(cx); let item_type = rustdoc_ty.def_id().and_then(|did| inline::build_ty(cx, did)); TypedefItem( - Typedef { type_: rustdoc_ty, generics: generics.clean(cx), item_type }, + box Typedef { type_: rustdoc_ty, generics: generics.clean(cx), item_type }, false, ) } @@ -2088,7 +2088,7 @@ fn clean_impl(impl_: &hir::Item<'_>, cx: &DocContext<'_>) -> Vec { _ => None, }); let make_item = |trait_: Option, for_: Type, items: Vec| { - let kind = ImplItem(Impl { + let kind = ImplItem(box Impl { unsafety, generics: generics.clean(cx), provided_trait_methods: provided.clone(), @@ -2263,7 +2263,7 @@ impl Clean for (&hir::ForeignItem<'_>, Option) { (generics.clean(cx), (&**decl, &names[..]).clean(cx)) }); let (all_types, ret_types) = get_all_types(&generics, &decl, cx); - ForeignFunctionItem(Function { + ForeignFunctionItem(box Function { decl, generics, header: hir::FnHeader { diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 0228d63ac00e6..cbb4d5dfd6c8d 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -305,24 +305,26 @@ crate enum ItemKind { StructItem(Struct), UnionItem(Union), EnumItem(Enum), - FunctionItem(Function), + FunctionItem(Box), ModuleItem(Module), - TypedefItem(Typedef, bool /* is associated type */), + TypedefItem(Box, bool /* is associated type */), OpaqueTyItem(OpaqueTy), StaticItem(Static), ConstantItem(Constant), TraitItem(Trait), TraitAliasItem(TraitAlias), - ImplItem(Impl), + // Impl is 400 bytes (!!), so box it to avoid penalizing other items + // FIXME(jyn514): calculate this information on demand instead + ImplItem(Box), /// A method signature only. Used for required methods in traits (ie, /// non-default-methods). - TyMethodItem(Function), + TyMethodItem(Box), /// A method with a 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/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index db04624dca848..d875bdca8ad13 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -3559,7 +3559,7 @@ fn render_deref_methods( .items .iter() .find_map(|item| match item.kind { - clean::TypedefItem(ref t, true) => Some(match *t { + clean::TypedefItem(ref t, true) => Some(match **t { clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_), _ => (&t.type_, &t.type_), }), @@ -4237,7 +4237,7 @@ fn sidebar_assoc_items(it: &clean::Item) -> String { { if let Some((target, real_target)) = impl_.inner_impl().items.iter().find_map(|item| match item.kind { - clean::TypedefItem(ref t, true) => Some(match *t { + clean::TypedefItem(ref t, true) => 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 c463481db86d2..1a4bd0b6916de 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -169,17 +169,17 @@ impl From for ItemEnum { StructFieldItem(f) => ItemEnum::StructFieldItem(f.into()), EnumItem(e) => ItemEnum::EnumItem(e.into()), VariantItem(v) => ItemEnum::VariantItem(v.into()), - FunctionItem(f) => ItemEnum::FunctionItem(f.into()), - ForeignFunctionItem(f) => ItemEnum::FunctionItem(f.into()), + FunctionItem(box f) => ItemEnum::FunctionItem(f.into()), + ForeignFunctionItem(box f) => ItemEnum::FunctionItem(f.into()), TraitItem(t) => ItemEnum::TraitItem(t.into()), TraitAliasItem(t) => ItemEnum::TraitAliasItem(t.into()), - MethodItem(m, _) => ItemEnum::MethodItem(m.into()), - TyMethodItem(m) => ItemEnum::MethodItem(m.into()), - ImplItem(i) => ItemEnum::ImplItem(i.into()), + MethodItem(box m, _) => ItemEnum::MethodItem(m.into()), + TyMethodItem(box m) => ItemEnum::MethodItem(m.into()), + ImplItem(box i) => ItemEnum::ImplItem(i.into()), StaticItem(s) => ItemEnum::StaticItem(s.into()), ForeignStaticItem(s) => ItemEnum::StaticItem(s.into()), ForeignTypeItem => ItemEnum::ForeignTypeItem, - TypedefItem(t, _) => ItemEnum::TypedefItem(t.into()), + TypedefItem(box t, _) => ItemEnum::TypedefItem(t.into()), OpaqueTyItem(t) => ItemEnum::OpaqueTyItem(t.into()), ConstantItem(c) => ItemEnum::ConstantItem(c.into()), MacroItem(m) => ItemEnum::MacroItem(m.source), diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 1e9bc67de04b8..16aeb44957547 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -56,7 +56,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate { // scan through included items ahead of time to splice in Deref targets to the "valid" sets for it in &new_items { - 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 cleaner.keep_item(for_) && trait_.def_id() == cx.tcx.lang_items().deref_trait() { let target = items .iter() @@ -76,7 +76,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate { } new_items.retain(|it| { - if let ImplItem(Impl { ref for_, ref trait_, ref blanket_impl, .. }) = it.kind { + if let ImplItem(box Impl { ref for_, ref trait_, ref blanket_impl, .. }) = it.kind { cleaner.keep_item(for_) || trait_.as_ref().map_or(false, |t| cleaner.keep_item(t)) || blanket_impl.is_some()