Skip to content

Commit 4bebdd7

Browse files
committed
box a bunch of large types
1 parent ec74653 commit 4bebdd7

File tree

16 files changed

+83
-79
lines changed

16 files changed

+83
-79
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,11 +2917,11 @@ pub enum ItemKind {
29172917
/// A static item (`static`).
29182918
///
29192919
/// E.g., `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";`.
2920-
Static(Static),
2920+
Static(Box<Static>),
29212921
/// A constant item (`const`).
29222922
///
29232923
/// E.g., `const FOO: i32 = 42;`.
2924-
Const(ConstItem),
2924+
Const(Box<ConstItem>),
29252925
/// A function declaration (`fn`).
29262926
///
29272927
/// E.g., `fn foo(bar: usize) -> usize { .. }`.
@@ -3037,7 +3037,7 @@ pub type AssocItem = Item<AssocItemKind>;
30373037
pub enum AssocItemKind {
30383038
/// An associated constant, `const $ident: $ty $def?;` where `def ::= "=" $expr? ;`.
30393039
/// If `def` is parsed, then the constant is provided, and otherwise required.
3040-
Const(ConstItem),
3040+
Const(Box<ConstItem>),
30413041
/// An associated function.
30423042
Fn(Box<Fn>),
30433043
/// An associated type.
@@ -3049,7 +3049,7 @@ pub enum AssocItemKind {
30493049
impl AssocItemKind {
30503050
pub fn defaultness(&self) -> Defaultness {
30513051
match *self {
3052-
Self::Const(ConstItem { defaultness, .. })
3052+
Self::Const(box ConstItem { defaultness, .. })
30533053
| Self::Fn(box Fn { defaultness, .. })
30543054
| Self::Type(box TyAlias { defaultness, .. }) => defaultness,
30553055
Self::MacCall(..) => Defaultness::Final,
@@ -3099,7 +3099,7 @@ impl From<ForeignItemKind> for ItemKind {
30993099
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
31003100
match foreign_item_kind {
31013101
ForeignItemKind::Static(a, b, c) => {
3102-
ItemKind::Static(Static { ty: a, mutability: b, expr: c })
3102+
ItemKind::Static(Static { ty: a, mutability: b, expr: c }.into())
31033103
}
31043104
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
31053105
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
@@ -3113,7 +3113,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
31133113

31143114
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
31153115
Ok(match item_kind {
3116-
ItemKind::Static(Static { ty: a, mutability: b, expr: c }) => {
3116+
ItemKind::Static(box Static { ty: a, mutability: b, expr: c }) => {
31173117
ForeignItemKind::Static(a, b, c)
31183118
}
31193119
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),
@@ -3132,8 +3132,8 @@ mod size_asserts {
31323132
use super::*;
31333133
use rustc_data_structures::static_assert_size;
31343134
// tidy-alphabetical-start
3135-
static_assert_size!(AssocItem, 104);
3136-
static_assert_size!(AssocItemKind, 32);
3135+
static_assert_size!(AssocItem, 88);
3136+
static_assert_size!(AssocItemKind, 16);
31373137
static_assert_size!(Attribute, 32);
31383138
static_assert_size!(Block, 32);
31393139
static_assert_size!(Expr, 72);

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
10301030
match kind {
10311031
ItemKind::ExternCrate(_orig_name) => {}
10321032
ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree),
1033-
ItemKind::Static(Static { ty, mutability: _, expr }) => {
1033+
ItemKind::Static(box Static { ty, mutability: _, expr }) => {
10341034
vis.visit_ty(ty);
10351035
visit_opt(expr, |expr| vis.visit_expr(expr));
10361036
}

compiler/rustc_ast/src/visit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
305305
match &item.kind {
306306
ItemKind::ExternCrate(_) => {}
307307
ItemKind::Use(use_tree) => visitor.visit_use_tree(use_tree, item.id, false),
308-
ItemKind::Static(Static { ty, mutability: _, expr })
309-
| ItemKind::Const(ConstItem { ty, expr, .. }) => {
308+
ItemKind::Static(box Static { ty, mutability: _, expr })
309+
| ItemKind::Const(box ConstItem { ty, expr, .. }) => {
310310
visitor.visit_ty(ty);
311311
walk_list!(visitor, visit_expr, expr);
312312
}
@@ -675,7 +675,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem,
675675
visitor.visit_ident(ident);
676676
walk_list!(visitor, visit_attribute, attrs);
677677
match kind {
678-
AssocItemKind::Const(ConstItem { ty, expr, .. }) => {
678+
AssocItemKind::Const(box ConstItem { ty, expr, .. }) => {
679679
visitor.visit_ty(ty);
680680
walk_list!(visitor, visit_expr, expr);
681681
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
229229

230230
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
231231
}
232-
ItemKind::Static(ast::Static { ty: t, mutability: m, expr: e }) => {
232+
ItemKind::Static(box ast::Static { ty: t, mutability: m, expr: e }) => {
233233
let (ty, body_id) = self.lower_const_item(t, span, e.as_deref());
234234
hir::ItemKind::Static(ty, *m, body_id)
235235
}
236-
ItemKind::Const(ast::ConstItem { ty, expr, .. }) => {
236+
ItemKind::Const(box ast::ConstItem { ty, expr, .. }) => {
237237
let (ty, body_id) = self.lower_const_item(ty, span, expr.as_deref());
238238
hir::ItemKind::Const(ty, body_id)
239239
}
@@ -708,7 +708,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
708708
let trait_item_def_id = hir_id.expect_owner();
709709

710710
let (generics, kind, has_default) = match &i.kind {
711-
AssocItemKind::Const(ConstItem { ty, expr, .. }) => {
711+
AssocItemKind::Const(box ConstItem { ty, expr, .. }) => {
712712
let ty =
713713
self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
714714
let body = expr.as_ref().map(|x| self.lower_const_body(i.span, Some(x)));
@@ -809,7 +809,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
809809
self.lower_attrs(hir_id, &i.attrs);
810810

811811
let (generics, kind) = match &i.kind {
812-
AssocItemKind::Const(ConstItem { ty, expr, .. }) => {
812+
AssocItemKind::Const(box ConstItem { ty, expr, .. }) => {
813813
let ty =
814814
self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
815815
(

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -983,14 +983,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
983983
self.err_handler().emit_err(errors::FieldlessUnion { span: item.span });
984984
}
985985
}
986-
ItemKind::Const(ConstItem { defaultness, expr: None, .. }) => {
986+
ItemKind::Const(box ConstItem { defaultness, expr: None, .. }) => {
987987
self.check_defaultness(item.span, *defaultness);
988988
self.session.emit_err(errors::ConstWithoutBody {
989989
span: item.span,
990990
replace_span: self.ending_semi_or_hi(item.span),
991991
});
992992
}
993-
ItemKind::Static(Static { expr: None, .. }) => {
993+
ItemKind::Static(box Static { expr: None, .. }) => {
994994
self.session.emit_err(errors::StaticWithoutBody {
995995
span: item.span,
996996
replace_span: self.ending_semi_or_hi(item.span),
@@ -1259,7 +1259,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12591259

12601260
if ctxt == AssocCtxt::Impl {
12611261
match &item.kind {
1262-
AssocItemKind::Const(ConstItem { expr: None, .. }) => {
1262+
AssocItemKind::Const(box ConstItem { expr: None, .. }) => {
12631263
self.session.emit_err(errors::AssocConstWithoutBody {
12641264
span: item.span,
12651265
replace_span: self.ending_semi_or_hi(item.span),

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'a> State<'a> {
157157
self.print_use_tree(tree);
158158
self.word(";");
159159
}
160-
ast::ItemKind::Static(Static { ty, mutability: mutbl, expr: body }) => {
160+
ast::ItemKind::Static(box Static { ty, mutability: mutbl, expr: body }) => {
161161
let def = ast::Defaultness::Final;
162162
self.print_item_const(
163163
item.ident,
@@ -168,7 +168,7 @@ impl<'a> State<'a> {
168168
def,
169169
);
170170
}
171-
ast::ItemKind::Const(ast::ConstItem { defaultness, ty, expr }) => {
171+
ast::ItemKind::Const(box ast::ConstItem { defaultness, ty, expr }) => {
172172
self.print_item_const(
173173
item.ident,
174174
None,
@@ -515,7 +515,7 @@ impl<'a> State<'a> {
515515
ast::AssocItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
516516
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
517517
}
518-
ast::AssocItemKind::Const(ast::ConstItem { defaultness, ty, expr }) => {
518+
ast::AssocItemKind::Const(box ast::ConstItem { defaultness, ty, expr }) => {
519519
self.print_item_const(ident, None, ty, expr.as_deref(), vis, *defaultness);
520520
}
521521
ast::AssocItemKind::Type(box ast::TyAlias {

compiler/rustc_builtin_macros/src/global_allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ pub fn expand(
2525
// FIXME - if we get deref patterns, use them to reduce duplication here
2626
let (item, is_stmt, ty_span) =
2727
if let Annotatable::Item(item) = &item
28-
&& let ItemKind::Static(ast::Static { ty, ..}) = &item.kind
28+
&& let ItemKind::Static(box ast::Static { ty, ..}) = &item.kind
2929
{
3030
(item, false, ecx.with_def_site_ctxt(ty.span))
3131
} else if let Annotatable::Stmt(stmt) = &item
3232
&& let StmtKind::Item(item) = &stmt.kind
33-
&& let ItemKind::Static(ast::Static { ty, ..}) = &item.kind
33+
&& let ItemKind::Static(box ast::Static { ty, ..}) = &item.kind
3434
{
3535
(item, true, ecx.with_def_site_ctxt(ty.span))
3636
} else {

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -254,25 +254,27 @@ pub fn expand_test_or_bench(
254254

255255
let location_info = get_location_info(cx, &item);
256256

257-
let mut test_const = cx.item(
258-
sp,
259-
Ident::new(item.ident.name, sp),
260-
thin_vec![
261-
// #[cfg(test)]
262-
cx.attr_nested_word(sym::cfg, sym::test, attr_sp),
263-
// #[rustc_test_marker = "test_case_sort_key"]
264-
cx.attr_name_value_str(sym::rustc_test_marker, test_path_symbol, attr_sp),
265-
],
266-
// const $ident: test::TestDescAndFn =
267-
ast::ItemKind::Const(ast::ConstItem {
268-
defaultness: ast::Defaultness::Final,
269-
ty: cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))),
270-
// test::TestDescAndFn {
271-
expr: Some(
272-
cx.expr_struct(
273-
sp,
274-
test_path("TestDescAndFn"),
275-
thin_vec![
257+
let mut test_const =
258+
cx.item(
259+
sp,
260+
Ident::new(item.ident.name, sp),
261+
thin_vec![
262+
// #[cfg(test)]
263+
cx.attr_nested_word(sym::cfg, sym::test, attr_sp),
264+
// #[rustc_test_marker = "test_case_sort_key"]
265+
cx.attr_name_value_str(sym::rustc_test_marker, test_path_symbol, attr_sp),
266+
],
267+
// const $ident: test::TestDescAndFn =
268+
ast::ItemKind::Const(
269+
ast::ConstItem {
270+
defaultness: ast::Defaultness::Final,
271+
ty: cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))),
272+
// test::TestDescAndFn {
273+
expr: Some(
274+
cx.expr_struct(
275+
sp,
276+
test_path("TestDescAndFn"),
277+
thin_vec![
276278
// desc: test::TestDesc {
277279
field(
278280
"desc",
@@ -359,10 +361,12 @@ pub fn expand_test_or_bench(
359361
// testfn: test::StaticTestFn(...) | test::StaticBenchFn(...)
360362
field("testfn", test_fn), // }
361363
],
362-
), // }
364+
), // }
365+
),
366+
}
367+
.into(),
363368
),
364-
}),
365-
);
369+
);
366370
test_const = test_const.map(|mut tc| {
367371
tc.vis.kind = ast::VisibilityKind::Public;
368372
tc

compiler/rustc_expand/src/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ impl<'a> ExtCtxt<'a> {
627627
span,
628628
name,
629629
AttrVec::new(),
630-
ast::ItemKind::Static(ast::Static { ty, mutability, expr: Some(expr) }),
630+
ast::ItemKind::Static(ast::Static { ty, mutability, expr: Some(expr) }.into()),
631631
)
632632
}
633633

@@ -643,7 +643,7 @@ impl<'a> ExtCtxt<'a> {
643643
span,
644644
name,
645645
AttrVec::new(),
646-
ast::ItemKind::Const(ast::ConstItem { defaultness, ty, expr: Some(expr) }),
646+
ast::ItemKind::Const(ast::ConstItem { defaultness, ty, expr: Some(expr) }.into()),
647647
)
648648
}
649649

compiler/rustc_lint/src/unused.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,8 @@ trait UnusedDelimLint {
805805
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
806806
use ast::ItemKind::*;
807807

808-
if let Const(ast::ConstItem { expr: Some(expr), .. })
809-
| Static(ast::Static { expr: Some(expr), .. }) = &item.kind
808+
if let Const(box ast::ConstItem { expr: Some(expr), .. })
809+
| Static(box ast::Static { expr: Some(expr), .. }) = &item.kind
810810
{
811811
self.check_unused_delims_expr(
812812
cx,

0 commit comments

Comments
 (0)