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

+8-8
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

+1-1
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

+3-3
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

+4-4
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

+3-3
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

+3-3
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

+2-2
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

+26-22
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

+2-2
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

+2-2
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,

compiler/rustc_parse/src/parser/item.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl<'a> Parser<'a> {
228228
self.bump(); // `static`
229229
let m = self.parse_mutability();
230230
let (ident, ty, expr) = self.parse_item_global(Some(m))?;
231-
(ident, ItemKind::Static(Static { ty, mutability: m, expr }))
231+
(ident, ItemKind::Static(Box::new(Static { ty, mutability: m, expr })))
232232
} else if let Const::Yes(const_span) = self.parse_constness(Case::Sensitive) {
233233
// CONST ITEM
234234
if self.token.is_keyword(kw::Impl) {
@@ -237,7 +237,7 @@ impl<'a> Parser<'a> {
237237
} else {
238238
self.recover_const_mut(const_span);
239239
let (ident, ty, expr) = self.parse_item_global(None)?;
240-
(ident, ItemKind::Const(ConstItem { defaultness: def_(), ty, expr }))
240+
(ident, ItemKind::Const(Box::new(ConstItem { defaultness: def_(), ty, expr })))
241241
}
242242
} else if self.check_keyword(kw::Trait) || self.check_auto_or_unsafe_trait_item() {
243243
// TRAIT ITEM
@@ -863,13 +863,13 @@ impl<'a> Parser<'a> {
863863
let kind = match AssocItemKind::try_from(kind) {
864864
Ok(kind) => kind,
865865
Err(kind) => match kind {
866-
ItemKind::Static(Static { ty, mutability: _, expr }) => {
866+
ItemKind::Static(box Static { ty, mutability: _, expr }) => {
867867
self.sess.emit_err(errors::AssociatedStaticItemNotAllowed { span });
868-
AssocItemKind::Const(ConstItem {
868+
AssocItemKind::Const(Box::new(ConstItem {
869869
defaultness: Defaultness::Final,
870870
ty,
871871
expr,
872-
})
872+
}))
873873
}
874874
_ => return self.error_bad_item_kind(span, &kind, "`trait`s or `impl`s"),
875875
},
@@ -1119,7 +1119,7 @@ impl<'a> Parser<'a> {
11191119
let kind = match ForeignItemKind::try_from(kind) {
11201120
Ok(kind) => kind,
11211121
Err(kind) => match kind {
1122-
ItemKind::Const(ConstItem { ty, expr, .. }) => {
1122+
ItemKind::Const(box ConstItem { ty, expr, .. }) => {
11231123
self.sess.emit_err(errors::ExternItemCannotBeConst {
11241124
ident_span: ident.span,
11251125
const_span: span.with_hi(ident.span.lo()),

compiler/rustc_resolve/src/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
688688
}
689689

690690
// These items live in the value namespace.
691-
ItemKind::Static(ast::Static { mutability, .. }) => {
691+
ItemKind::Static(box ast::Static { mutability, .. }) => {
692692
let res = Res::Def(DefKind::Static(mutability), def_id);
693693
self.r.define(parent, ident, ValueNS, (res, vis, sp, expansion));
694694
}

compiler/rustc_resolve/src/late.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2346,8 +2346,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23462346
});
23472347
}
23482348

2349-
ItemKind::Static(ast::Static { ref ty, ref expr, .. })
2350-
| ItemKind::Const(ast::ConstItem { ref ty, ref expr, .. }) => {
2349+
ItemKind::Static(box ast::Static { ref ty, ref expr, .. })
2350+
| ItemKind::Const(box ast::ConstItem { ref ty, ref expr, .. }) => {
23512351
self.with_static_rib(|this| {
23522352
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| {
23532353
this.visit_ty(ty);
@@ -2625,7 +2625,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26252625
for item in trait_items {
26262626
self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
26272627
match &item.kind {
2628-
AssocItemKind::Const(ast::ConstItem { ty, expr, .. }) => {
2628+
AssocItemKind::Const(box ast::ConstItem { ty, expr, .. }) => {
26292629
self.visit_ty(ty);
26302630
// Only impose the restrictions of `ConstRibKind` for an
26312631
// actual constant expression in a provided default.
@@ -2800,7 +2800,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
28002800
use crate::ResolutionError::*;
28012801
self.resolve_doc_links(&item.attrs, MaybeExported::ImplItem(trait_id.ok_or(&item.vis)));
28022802
match &item.kind {
2803-
AssocItemKind::Const(ast::ConstItem { ty, expr, .. }) => {
2803+
AssocItemKind::Const(box ast::ConstItem { ty, expr, .. }) => {
28042804
debug!("resolve_implementation AssocItemKind::Const");
28052805
// If this is a trait impl, ensure the const
28062806
// exists in trait

src/tools/clippy/clippy_lints/src/redundant_static_lifetimes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ impl EarlyLintPass for RedundantStaticLifetimes {
100100
}
101101

102102
if !item.span.from_expansion() {
103-
if let ItemKind::Const(ConstItem { ty: ref var_type, .. }) = item.kind {
103+
if let ItemKind::Const(box ConstItem { ty: ref var_type, .. }) = item.kind {
104104
Self::visit_type(var_type, cx, "constants have by default a `'static` lifetime");
105105
// Don't check associated consts because `'static` cannot be elided on those (issue
106106
// #2438)
107107
}
108108

109-
if let ItemKind::Static(Static{ ty: ref var_type,.. }) = item.kind {
109+
if let ItemKind::Static(box Static { ty: ref var_type,.. }) = item.kind {
110110
Self::visit_type(var_type, cx, "statics have by default a `'static` lifetime");
111111
}
112112
}

0 commit comments

Comments
 (0)