Skip to content

Commit 96c051f

Browse files
committed
Box TypedefItem, ImplItem, AssocTypeItem variants of ItemKind
This reduces ItemKind size from 224 bytes to 160 bytes.
1 parent 0bf65c7 commit 96c051f

File tree

10 files changed

+37
-37
lines changed

10 files changed

+37
-37
lines changed

src/librustdoc/clean/auto_trait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
117117
attrs: Default::default(),
118118
visibility: Inherited,
119119
item_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
120-
kind: Box::new(ImplItem(Impl {
120+
kind: Box::new(ImplItem(Box::new(Impl {
121121
unsafety: hir::Unsafety::Normal,
122122
generics: new_generics,
123123
trait_: Some(trait_ref.clean(self.cx)),
124124
for_: clean_middle_ty(ty, self.cx, None),
125125
items: Vec::new(),
126126
polarity,
127127
kind: ImplKind::Auto,
128-
})),
128+
}))),
129129
cfg: None,
130130
})
131131
}

src/librustdoc/clean/blanket_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
106106
attrs: Default::default(),
107107
visibility: Inherited,
108108
item_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
109-
kind: Box::new(ImplItem(Impl {
109+
kind: Box::new(ImplItem(Box::new(Impl {
110110
unsafety: hir::Unsafety::Normal,
111111
generics: clean_ty_generics(
112112
cx,
@@ -124,7 +124,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
124124
.collect::<Vec<_>>(),
125125
polarity: ty::ImplPolarity::Positive,
126126
kind: ImplKind::Blanket(Box::new(clean_middle_ty(trait_ref.0.self_ty(), cx, None))),
127-
})),
127+
}))),
128128
cfg: None,
129129
});
130130
}

src/librustdoc/clean/inline.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,15 @@ fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union {
260260
clean::Union { generics, fields }
261261
}
262262

263-
fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::Typedef {
263+
fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> Box<clean::Typedef> {
264264
let predicates = cx.tcx.explicit_predicates_of(did);
265265
let type_ = clean_middle_ty(cx.tcx.type_of(did), cx, Some(did));
266266

267-
clean::Typedef {
267+
Box::new(clean::Typedef {
268268
type_,
269269
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates),
270270
item_type: None,
271-
}
271+
})
272272
}
273273

274274
/// Builds all inherent implementations of an ADT (struct/union/enum) or Trait item/path/reexport.
@@ -493,7 +493,7 @@ pub(crate) fn build_impl(
493493
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
494494
did,
495495
None,
496-
clean::ImplItem(clean::Impl {
496+
clean::ImplItem(Box::new(clean::Impl {
497497
unsafety: hir::Unsafety::Normal,
498498
generics,
499499
trait_,
@@ -505,7 +505,7 @@ pub(crate) fn build_impl(
505505
} else {
506506
ImplKind::Normal
507507
},
508-
}),
508+
})),
509509
Box::new(merged_attrs),
510510
cx,
511511
cfg,

src/librustdoc/clean/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1068,11 +1068,11 @@ impl<'tcx> Clean<'tcx, Item> for hir::TraitItem<'tcx> {
10681068
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect();
10691069
let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, default), cx, None);
10701070
AssocTypeItem(
1071-
Typedef {
1071+
Box::new(Typedef {
10721072
type_: clean_ty(default, cx),
10731073
generics,
10741074
item_type: Some(item_type),
1075-
},
1075+
}),
10761076
bounds,
10771077
)
10781078
}
@@ -1109,7 +1109,7 @@ impl<'tcx> Clean<'tcx, Item> for hir::ImplItem<'tcx> {
11091109
let generics = self.generics.clean(cx);
11101110
let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, hir_ty), cx, None);
11111111
AssocTypeItem(
1112-
Typedef { type_, generics, item_type: Some(item_type) },
1112+
Box::new(Typedef { type_, generics, item_type: Some(item_type) }),
11131113
Vec::new(),
11141114
)
11151115
}
@@ -1282,7 +1282,7 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
12821282

12831283
if self.defaultness.has_value() {
12841284
AssocTypeItem(
1285-
Typedef {
1285+
Box::new(Typedef {
12861286
type_: clean_middle_ty(
12871287
tcx.type_of(self.def_id),
12881288
cx,
@@ -1291,7 +1291,7 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
12911291
generics,
12921292
// FIXME: should we obtain the Type from HIR and pass it on here?
12931293
item_type: None,
1294-
},
1294+
}),
12951295
bounds,
12961296
)
12971297
} else {
@@ -1300,11 +1300,11 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
13001300
} else {
13011301
// FIXME: when could this happen? Associated items in inherent impls?
13021302
AssocTypeItem(
1303-
Typedef {
1303+
Box::new(Typedef {
13041304
type_: clean_middle_ty(tcx.type_of(self.def_id), cx, Some(self.def_id)),
13051305
generics: Generics { params: Vec::new(), where_predicates: Vec::new() },
13061306
item_type: None,
1307-
},
1307+
}),
13081308
Vec::new(),
13091309
)
13101310
}
@@ -1949,11 +1949,11 @@ fn clean_maybe_renamed_item<'tcx>(
19491949
ItemKind::TyAlias(hir_ty, generics) => {
19501950
let rustdoc_ty = clean_ty(hir_ty, cx);
19511951
let ty = clean_middle_ty(hir_ty_to_ty(cx.tcx, hir_ty), cx, None);
1952-
TypedefItem(Typedef {
1952+
TypedefItem(Box::new(Typedef {
19531953
type_: rustdoc_ty,
19541954
generics: generics.clean(cx),
19551955
item_type: Some(ty),
1956-
})
1956+
}))
19571957
}
19581958
ItemKind::Enum(ref def, generics) => EnumItem(Enum {
19591959
variants: def.variants.iter().map(|v| v.clean(cx)).collect(),
@@ -2041,7 +2041,7 @@ fn clean_impl<'tcx>(
20412041
_ => None,
20422042
});
20432043
let mut make_item = |trait_: Option<Path>, for_: Type, items: Vec<Item>| {
2044-
let kind = ImplItem(Impl {
2044+
let kind = ImplItem(Box::new(Impl {
20452045
unsafety: impl_.unsafety,
20462046
generics: impl_.generics.clean(cx),
20472047
trait_,
@@ -2053,7 +2053,7 @@ fn clean_impl<'tcx>(
20532053
} else {
20542054
ImplKind::Normal
20552055
},
2056-
});
2056+
}));
20572057
Item::from_hir_id_and_parts(hir_id, None, kind, cx)
20582058
};
20592059
if let Some(type_alias) = type_alias {

src/librustdoc/clean/types.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ impl Item {
430430
};
431431
match kind {
432432
ItemKind::ModuleItem(Module { span, .. }) => *span,
433-
ItemKind::ImplItem(Impl { kind: ImplKind::Auto, .. }) => Span::dummy(),
434-
ItemKind::ImplItem(Impl { kind: ImplKind::Blanket(_), .. }) => {
433+
ItemKind::ImplItem(box Impl { kind: ImplKind::Auto, .. }) => Span::dummy(),
434+
ItemKind::ImplItem(box Impl { kind: ImplKind::Blanket(_), .. }) => {
435435
if let ItemId::Blanket { impl_id, .. } = self.item_id {
436436
rustc_span(impl_id, tcx)
437437
} else {
@@ -732,13 +732,13 @@ pub(crate) enum ItemKind {
732732
EnumItem(Enum),
733733
FunctionItem(Function),
734734
ModuleItem(Module),
735-
TypedefItem(Typedef),
735+
TypedefItem(Box<Typedef>),
736736
OpaqueTyItem(OpaqueTy),
737737
StaticItem(Static),
738738
ConstantItem(Constant),
739739
TraitItem(Trait),
740740
TraitAliasItem(TraitAlias),
741-
ImplItem(Impl),
741+
ImplItem(Box<Impl>),
742742
/// A required method in a trait declaration meaning it's only a function signature.
743743
TyMethodItem(Function),
744744
/// A method in a trait impl or a provided method in a trait declaration.
@@ -765,7 +765,7 @@ pub(crate) enum ItemKind {
765765
/// The bounds may be non-empty if there is a `where` clause.
766766
TyAssocTypeItem(Box<Generics>, Vec<GenericBound>),
767767
/// An associated type in a trait impl or a provided one in a trait declaration.
768-
AssocTypeItem(Typedef, Vec<GenericBound>),
768+
AssocTypeItem(Box<Typedef>, Vec<GenericBound>),
769769
/// An item that has been stripped by a rustdoc pass
770770
StrippedItem(Box<ItemKind>),
771771
KeywordItem,

src/librustdoc/formats/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ enum ParentStackItem {
536536
impl ParentStackItem {
537537
fn new(item: &clean::Item) -> Self {
538538
match &*item.kind {
539-
clean::ItemKind::ImplItem(clean::Impl { for_, trait_, generics, kind, .. }) => {
539+
clean::ItemKind::ImplItem(box clean::Impl { for_, trait_, generics, kind, .. }) => {
540540
ParentStackItem::Impl {
541541
for_: for_.clone(),
542542
trait_: trait_.clone(),

src/librustdoc/html/render/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ fn render_deref_methods(
11601160
.items
11611161
.iter()
11621162
.find_map(|item| match *item.kind {
1163-
clean::AssocTypeItem(ref t, _) => Some(match *t {
1163+
clean::AssocTypeItem(box ref t, _) => Some(match *t {
11641164
clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
11651165
_ => (&t.type_, &t.type_),
11661166
}),
@@ -2054,7 +2054,7 @@ fn sidebar_deref_methods(
20542054
debug!("found Deref: {:?}", impl_);
20552055
if let Some((target, real_target)) =
20562056
impl_.inner_impl().items.iter().find_map(|item| match *item.kind {
2057-
clean::AssocTypeItem(ref t, _) => Some(match *t {
2057+
clean::AssocTypeItem(box ref t, _) => Some(match *t {
20582058
clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
20592059
_ => (&t.type_, &t.type_),
20602060
}),

src/librustdoc/json/conversions.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,10 @@ impl FromWithTcx<clean::Trait> for Trait {
568568
}
569569
}
570570

571-
impl FromWithTcx<clean::Impl> for Impl {
572-
fn from_tcx(impl_: clean::Impl, tcx: TyCtxt<'_>) -> Self {
571+
impl FromWithTcx<Box<clean::Impl>> for Impl {
572+
fn from_tcx(impl_: Box<clean::Impl>, tcx: TyCtxt<'_>) -> Self {
573573
let provided_trait_methods = impl_.provided_trait_methods(tcx);
574-
let clean::Impl { unsafety, generics, trait_, for_, items, polarity, kind } = impl_;
574+
let clean::Impl { unsafety, generics, trait_, for_, items, polarity, kind } = *impl_;
575575
// FIXME: should `trait_` be a clean::Path equivalent in JSON?
576576
let trait_ = trait_.map(|path| clean::Type::Path { path }.into_tcx(tcx));
577577
// FIXME: use something like ImplKind in JSON?
@@ -721,9 +721,9 @@ pub(crate) fn from_macro_kind(kind: rustc_span::hygiene::MacroKind) -> MacroKind
721721
}
722722
}
723723

724-
impl FromWithTcx<clean::Typedef> for Typedef {
725-
fn from_tcx(typedef: clean::Typedef, tcx: TyCtxt<'_>) -> Self {
726-
let clean::Typedef { type_, generics, item_type: _ } = typedef;
724+
impl FromWithTcx<Box<clean::Typedef>> for Typedef {
725+
fn from_tcx(typedef: Box<clean::Typedef>, tcx: TyCtxt<'_>) -> Self {
726+
let clean::Typedef { type_, generics, item_type: _ } = *typedef;
727727
Typedef { type_: type_.into_tcx(tcx), generics: generics.into_tcx(tcx) }
728728
}
729729
}

src/librustdoc/passes/check_doc_test_visibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub(crate) fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -
7171
| clean::PrimitiveItem(_)
7272
| clean::KeywordItem
7373
// check for trait impl
74-
| clean::ImplItem(clean::Impl { trait_: Some(_), .. })
74+
| clean::ImplItem(box clean::Impl { trait_: Some(_), .. })
7575
)
7676
{
7777
return false;

src/librustdoc/passes/collect_trait_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
146146

147147
// scan through included items ahead of time to splice in Deref targets to the "valid" sets
148148
for it in new_items_external.iter().chain(new_items_local.iter()) {
149-
if let ImplItem(Impl { ref for_, ref trait_, ref items, .. }) = *it.kind {
149+
if let ImplItem(box Impl { ref for_, ref trait_, ref items, .. }) = *it.kind {
150150
if trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait()
151151
&& cleaner.keep_impl(for_, true)
152152
{
@@ -187,7 +187,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
187187

188188
// Filter out external items that are not needed
189189
new_items_external.retain(|it| {
190-
if let ImplItem(Impl { ref for_, ref trait_, ref kind, .. }) = *it.kind {
190+
if let ImplItem(box Impl { ref for_, ref trait_, ref kind, .. }) = *it.kind {
191191
cleaner.keep_impl(
192192
for_,
193193
trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait(),

0 commit comments

Comments
 (0)