From 36487c75956bfe2476d1f813dff6903b104066b9 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Jul 2026 14:58:41 +1000 Subject: [PATCH] Shrink `ast::Expr` From 72 bytes to 64 bytes, by boxing `ForLoop`, which is the biggest variant. There are now 11 `ExprKind` variants that are 31 bytes, so future improvements here will be very difficult. --- compiler/rustc_ast/src/ast.rs | 21 +++++++++-------- compiler/rustc_ast/src/util/classify.rs | 5 +++- compiler/rustc_ast/src/visit.rs | 2 +- compiler/rustc_ast_lowering/src/expr.rs | 2 +- .../rustc_ast_pretty/src/pprust/state/expr.rs | 2 +- compiler/rustc_lint/src/unused.rs | 6 ++--- compiler/rustc_parse/src/parser/expr.rs | 22 ++++++++++++++---- compiler/rustc_resolve/src/late.rs | 2 +- .../clippy/clippy_utils/src/ast_utils/mod.rs | 23 ++++++------------- src/tools/rustfmt/src/expr.rs | 10 ++------ tests/ui/stats/input-stats.stderr | 16 ++++++------- 11 files changed, 57 insertions(+), 54 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 3293da27d2912..deaafa8ab2e36 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1655,6 +1655,15 @@ impl From> for Expr { } } +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] +pub struct ForLoop { + pub pat: Box, + pub iter: Box, + pub body: Box, + pub label: Option