From f4805e83a76f2ad3971e20055d07632406ba1b80 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Jul 2026 13:07:47 +1000 Subject: [PATCH 1/5] Use `ThinVec` in `Expr::OffsetOf` Because we use `ThinVec` rather than `Vec` almost everywhere else in the AST. --- compiler/rustc_ast/src/ast.rs | 2 +- compiler/rustc_ast/src/visit.rs | 1 + compiler/rustc_parse/src/parser/expr.rs | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index bd5ce5d18b839..e19aeb11b46ad 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1868,7 +1868,7 @@ pub enum ExprKind { /// /// Usually not written directly in user code but /// indirectly via the macro `core::mem::offset_of!(...)`. - OffsetOf(Box, Vec), + OffsetOf(Box, ThinVec), /// A macro invocation; pre-expansion. MacCall(Box), diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 1e96d1d52f7eb..8b96bbde82215 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -386,6 +386,7 @@ macro_rules! common_visitor_and_walkers { impl_visitable_list!(<$($lt)? $($mut)?> ThinVec, ThinVec, + ThinVec, ThinVec<(Ident, Option)>, ThinVec<(NodeId, Path)>, ThinVec, diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 60a94345c5325..df1877b82cb93 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1154,8 +1154,8 @@ impl<'a> Parser<'a> { /// Parse the field access used in offset_of, matched by `$(e:expr)+`. /// Currently returns a list of idents. However, it should be possible in /// future to also do array indices, which might be arbitrary expressions. - pub(crate) fn parse_floating_field_access(&mut self) -> PResult<'a, Vec> { - let mut fields = Vec::new(); + pub(crate) fn parse_floating_field_access(&mut self) -> PResult<'a, ThinVec> { + let mut fields = ThinVec::new(); let mut trailing_dot = None; loop { From 994c964756206600b83ff851c2e451c4bbe27021 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Jul 2026 13:36:47 +1000 Subject: [PATCH 2/5] Add some more AST size assertions --- compiler/rustc_ast/src/ast.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index e19aeb11b46ad..fff4d8e7ea799 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -4391,27 +4391,37 @@ mod size_asserts { // tidy-alphabetical-start static_assert_size!(AssocItem, 80); static_assert_size!(AssocItemKind, 16); + static_assert_size!(AttrKind, 16); static_assert_size!(Attribute, 32); static_assert_size!(Block, 32); static_assert_size!(Expr, 72); static_assert_size!(ExprKind, 40); static_assert_size!(Fn, 192); + static_assert_size!(FnDecl, 24); + static_assert_size!(FnHeader, 76); + static_assert_size!(FnSig, 96); static_assert_size!(ForeignItem, 80); static_assert_size!(ForeignItemKind, 16); static_assert_size!(GenericArg, 24); + static_assert_size!(GenericArgs, 40); static_assert_size!(GenericBound, 88); + static_assert_size!(GenericParam, 96); static_assert_size!(Generics, 40); static_assert_size!(Impl, 80); static_assert_size!(Item, 152); static_assert_size!(ItemKind, 88); + static_assert_size!(Lifetime, 16); static_assert_size!(LitKind, 24); static_assert_size!(Local, 96); + static_assert_size!(MetaItem, 88); + static_assert_size!(MetaItemKind, 40); static_assert_size!(MetaItemLit, 40); static_assert_size!(Param, 40); static_assert_size!(Pat, 80); static_assert_size!(PatKind, 56); static_assert_size!(Path, 24); static_assert_size!(PathSegment, 24); + static_assert_size!(QSelf, 24); static_assert_size!(Stmt, 32); static_assert_size!(StmtKind, 16); static_assert_size!(TraitImplHeader, 72); From 114e832da5efc5bbe754b6dd4eacccfae0874283 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Jul 2026 13:24:25 +1000 Subject: [PATCH 3/5] Use `ThinVec` in `GenericBounds` Because we use `ThinVec` rather than `Vec` almost everywhere else in the AST. --- compiler/rustc_ast/src/ast.rs | 6 +++--- compiler/rustc_ast/src/visit.rs | 1 + compiler/rustc_builtin_macros/src/deriving/debug.rs | 2 +- .../rustc_builtin_macros/src/deriving/generic/mod.rs | 6 +++--- compiler/rustc_parse/src/parser/generics.rs | 12 ++++++------ compiler/rustc_parse/src/parser/item.rs | 5 +++-- compiler/rustc_parse/src/parser/ty.rs | 8 ++++---- compiler/rustc_resolve/src/late/diagnostics.rs | 4 ++-- tests/ui/stats/input-stats.stderr | 8 ++++---- 9 files changed, 27 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index fff4d8e7ea799..3e1fff594040e 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -407,7 +407,7 @@ impl GenericBound { } } -pub type GenericBounds = Vec; +pub type GenericBounds = ThinVec; /// Specifies the enforced ordering for generic parameters. In the future, /// if we wanted to relax this order, we could override `PartialEq` and @@ -1534,7 +1534,7 @@ impl Expr { let (Some(lhs), Some(rhs)) = (lhs.to_bound(), rhs.to_bound()) else { return None; }; - TyKind::TraitObject(vec![lhs, rhs], TraitObjectSyntax::None) + TyKind::TraitObject(thin_vec![lhs, rhs], TraitObjectSyntax::None) } ExprKind::Underscore => TyKind::Infer, @@ -4405,7 +4405,7 @@ mod size_asserts { static_assert_size!(GenericArg, 24); static_assert_size!(GenericArgs, 40); static_assert_size!(GenericBound, 88); - static_assert_size!(GenericParam, 96); + static_assert_size!(GenericParam, 80); static_assert_size!(Generics, 40); static_assert_size!(Impl, 80); static_assert_size!(Item, 152); diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 8b96bbde82215..fb4e76321d150 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -386,6 +386,7 @@ macro_rules! common_visitor_and_walkers { impl_visitable_list!(<$($lt)? $($mut)?> ThinVec, ThinVec, + ThinVec, ThinVec, ThinVec<(Ident, Option)>, ThinVec<(NodeId, Path)>, diff --git a/compiler/rustc_builtin_macros/src/deriving/debug.rs b/compiler/rustc_builtin_macros/src/deriving/debug.rs index 004b13bcc333d..2436800d0099d 100644 --- a/compiler/rustc_builtin_macros/src/deriving/debug.rs +++ b/compiler/rustc_builtin_macros/src/deriving/debug.rs @@ -167,7 +167,7 @@ fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> let ty_dyn_debug = cx.ty( span, ast::TyKind::TraitObject( - vec![cx.trait_bound(path_debug, false)], + thin_vec![cx.trait_bound(path_debug, false)], ast::TraitObjectSyntax::Dyn, ), ); diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index ff6b15b173ed1..1577db640502c 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -617,7 +617,7 @@ impl<'a> TraitDef<'a> { ident, generics: Generics::default(), after_where_clause: ast::WhereClause::default(), - bounds: Vec::new(), + bounds: ThinVec::new(), ty: Some(type_def.to_ty(cx, self.span, type_ident, generics)), })), tokens: None, @@ -639,7 +639,7 @@ impl<'a> TraitDef<'a> { // Extra restrictions on the generics parameters to the // type being derived upon. let span = param.ident.span.with_ctxt(ctxt); - let bounds: Vec<_> = self + let bounds: ThinVec<_> = self .additional_bounds .iter() .map(|p| { @@ -723,7 +723,7 @@ impl<'a> TraitDef<'a> { { continue; } - let mut bounds: Vec<_> = self + let mut bounds: ThinVec<_> = self .additional_bounds .iter() .map(|p| { diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs index e2df607fd0f86..506607f57191d 100644 --- a/compiler/rustc_parse/src/parser/generics.rs +++ b/compiler/rustc_parse/src/parser/generics.rs @@ -26,7 +26,7 @@ impl<'a> Parser<'a> { /// BOUND = LT_BOUND (e.g., `'a`) /// ``` fn parse_lt_param_bounds(&mut self) -> GenericBounds { - let mut lifetimes = Vec::new(); + let mut lifetimes = ThinVec::new(); while self.check_lifetime() { lifetimes.push(ast::GenericBound::Outlives(self.expect_lifetime())); @@ -86,7 +86,7 @@ impl<'a> Parser<'a> { } self.parse_generic_bounds()? } else { - Vec::new() + ThinVec::new() }; let default = if self.eat(exp!(Eq)) { Some(self.parse_ty()?) } else { None }; @@ -125,7 +125,7 @@ impl<'a> Parser<'a> { ident, id: ast::DUMMY_NODE_ID, attrs: preceding_attrs, - bounds: Vec::new(), + bounds: ThinVec::new(), kind: GenericParamKind::Const { ty, span, default: None }, is_placeholder: false, colon_span: None, @@ -148,7 +148,7 @@ impl<'a> Parser<'a> { ident, id: ast::DUMMY_NODE_ID, attrs: preceding_attrs, - bounds: Vec::new(), + bounds: ThinVec::new(), kind: GenericParamKind::Const { ty, span, default }, is_placeholder: false, colon_span: None, @@ -189,7 +189,7 @@ impl<'a> Parser<'a> { ident, id: ast::DUMMY_NODE_ID, attrs: preceding_attrs, - bounds: Vec::new(), + bounds: ThinVec::new(), kind: GenericParamKind::Const { ty, span, default }, is_placeholder: false, colon_span: None, @@ -225,7 +225,7 @@ impl<'a> Parser<'a> { let (colon_span, bounds) = if this.eat(exp!(Colon)) { (Some(this.prev_token.span), this.parse_lt_param_bounds()) } else { - (None, Vec::new()) + (None, ThinVec::new()) }; if this.check_noexpect(&token::Eq) && this.look_ahead(1, |t| t.is_lifetime()) { diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 16fed9c6c273b..6f5c4c874d83b 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1135,7 +1135,7 @@ impl<'a> Parser<'a> { // Parse optional colon and supertrait bounds. let had_colon = self.eat(exp!(Colon)); let span_at_colon = self.prev_token.span; - let bounds = if had_colon { self.parse_generic_bounds()? } else { Vec::new() }; + let bounds = if had_colon { self.parse_generic_bounds()? } else { ThinVec::new() }; let span_before_eq = self.prev_token.span; if self.eat(exp!(Eq)) { @@ -1253,7 +1253,8 @@ impl<'a> Parser<'a> { let mut generics = self.parse_generics()?; // Parse optional colon and param bounds. - let bounds = if self.eat(exp!(Colon)) { self.parse_generic_bounds()? } else { Vec::new() }; + let bounds = + if self.eat(exp!(Colon)) { self.parse_generic_bounds()? } else { ThinVec::new() }; generics.where_clause = self.parse_where_clause()?; let ty = if self.eat(exp!(Eq)) { Some(self.parse_ty()?) } else { None }; diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 8a881c6f8b568..9c873711e2f87 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -576,7 +576,7 @@ impl<'a> Parser<'a> { lo.to(self.prev_token.span), parens, ); - let bounds = vec![GenericBound::Trait(poly_trait_ref)]; + let bounds = thin_vec![GenericBound::Trait(poly_trait_ref)]; self.parse_remaining_bounds(bounds, parse_plus) } @@ -1080,7 +1080,7 @@ impl<'a> Parser<'a> { /// Only if `allow_plus` this parses a `+`-separated list of bounds (trailing `+` is admitted). /// Otherwise, this only parses a single bound or none. fn parse_generic_bounds_common(&mut self, allow_plus: AllowPlus) -> PResult<'a, GenericBounds> { - let mut bounds = Vec::new(); + let mut bounds = ThinVec::new(); // In addition to looping while we find generic bounds: // We continue even if we find a keyword. This is necessary for error recovery on, @@ -1432,7 +1432,7 @@ impl<'a> Parser<'a> { // Someone has written something like `&dyn (Trait + Other)`. The correct code // would be `&(dyn Trait + Other)` if self.token.is_like_plus() && leading_token.is_keyword(kw::Dyn) { - let bounds = vec![]; + let bounds = thin_vec![]; self.parse_remaining_bounds(bounds, true)?; self.expect(exp!(CloseParen))?; self.dcx().emit_err(errors::IncorrectParensTraitBounds { @@ -1617,7 +1617,7 @@ impl<'a> Parser<'a> { id: lt.id, ident: lt.ident, attrs: ast::AttrVec::new(), - bounds: Vec::new(), + bounds: ThinVec::new(), is_placeholder: false, kind: ast::GenericParamKind::Lifetime, colon_span: None, diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 8c5c7f5b2d76d..668278f13d9cf 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -28,7 +28,7 @@ use rustc_session::{Session, lint}; use rustc_span::edit_distance::{edit_distance, find_best_match_for_name}; use rustc_span::edition::Edition; use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, kw, sym}; -use thin_vec::ThinVec; +use thin_vec::{ThinVec, thin_vec}; use tracing::debug; use super::NoConstantGenericsReason; @@ -4522,7 +4522,7 @@ fn mk_where_bound_predicate( let new_where_bound_predicate = ast::WhereBoundPredicate { bound_generic_params: ThinVec::new(), bounded_ty: Box::new(ty.clone()), - bounds: vec![ast::GenericBound::Trait(ast::PolyTraitRef { + bounds: thin_vec![ast::GenericBound::Trait(ast::PolyTraitRef { bound_generic_params: ThinVec::new(), modifiers: ast::TraitBoundModifiers::NONE, trait_ref: ast::TraitRef { diff --git a/tests/ui/stats/input-stats.stderr b/tests/ui/stats/input-stats.stderr index b4d8277a46c00..f4c6808431687 100644 --- a/tests/ui/stats/input-stats.stderr +++ b/tests/ui/stats/input-stats.stderr @@ -27,7 +27,7 @@ ast-stats Pat 560 (NN.N%) 7 80 ast-stats - Struct 80 (NN.N%) 1 ast-stats - Wild 80 (NN.N%) 1 ast-stats - Ident 400 (NN.N%) 5 -ast-stats GenericParam 480 (NN.N%) 5 96 +ast-stats GenericParam 400 (NN.N%) 5 80 ast-stats GenericBound 352 (NN.N%) 4 88 ast-stats - Trait 352 (NN.N%) 4 ast-stats AssocItem 320 (NN.N%) 4 80 @@ -50,14 +50,14 @@ ast-stats Local 96 (NN.N%) 1 96 ast-stats Arm 96 (NN.N%) 2 48 ast-stats ForeignItem 80 (NN.N%) 1 80 ast-stats - Fn 80 (NN.N%) 1 -ast-stats WherePredicate 72 (NN.N%) 1 72 -ast-stats - BoundPredicate 72 (NN.N%) 1 +ast-stats WherePredicate 56 (NN.N%) 1 56 +ast-stats - BoundPredicate 56 (NN.N%) 1 ast-stats ExprField 48 (NN.N%) 1 48 ast-stats GenericArgs 40 (NN.N%) 1 40 ast-stats - AngleBracketed 40 (NN.N%) 1 ast-stats Crate 40 (NN.N%) 1 40 ast-stats ---------------------------------------------------------------- -ast-stats Total 7_624 127 +ast-stats Total 7_528 127 ast-stats ================================================================ hir-stats ================================================================ hir-stats HIR STATS: input_stats From 1b49395d2214d25a04d18c40d947076cdf739a31 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Jul 2026 13:56:05 +1000 Subject: [PATCH 4/5] XXX: Box --- compiler/rustc_ast/src/ast.rs | 65 ++++++++++--------- compiler/rustc_ast/src/attr/mod.rs | 4 +- compiler/rustc_ast/src/visit.rs | 2 +- compiler/rustc_ast_lowering/src/item.rs | 2 +- compiler/rustc_ast_lowering/src/lib.rs | 6 +- .../rustc_ast_pretty/src/pprust/state/item.rs | 4 +- compiler/rustc_attr_parsing/src/parser.rs | 5 +- compiler/rustc_builtin_macros/src/assert.rs | 4 +- .../src/assert/context.rs | 4 +- compiler/rustc_builtin_macros/src/autodiff.rs | 2 +- .../src/deriving/coerce_pointee.rs | 2 +- .../src/deriving/generic/mod.rs | 3 +- .../src/deriving/generic/ty.rs | 4 +- .../rustc_builtin_macros/src/edition_panic.rs | 4 +- .../rustc_builtin_macros/src/test_harness.rs | 6 +- compiler/rustc_expand/src/base.rs | 2 +- compiler/rustc_expand/src/build.rs | 35 +++++----- compiler/rustc_expand/src/expand.rs | 8 +-- compiler/rustc_expand/src/placeholders.rs | 2 +- compiler/rustc_expand/src/stats.rs | 2 +- .../rustc_hir/src/attrs/data_structures.rs | 2 +- .../rustc_parse/src/parser/diagnostics.rs | 27 ++++---- compiler/rustc_parse/src/parser/expr.rs | 12 ++-- compiler/rustc_parse/src/parser/item.rs | 2 +- compiler/rustc_parse/src/parser/mod.rs | 28 +++----- .../rustc_parse/src/parser/nonterminal.rs | 4 +- compiler/rustc_parse/src/parser/pat.rs | 10 ++- compiler/rustc_parse/src/parser/path.rs | 26 ++++---- compiler/rustc_parse/src/parser/stmt.rs | 7 +- compiler/rustc_parse/src/parser/ty.rs | 8 +-- compiler/rustc_resolve/src/late.rs | 2 +- .../rustc_resolve/src/late/diagnostics.rs | 6 +- compiler/rustc_resolve/src/lib.rs | 6 +- .../clippy/clippy_lints/src/visibility.rs | 4 +- tests/ui-fulldeps/pprust-expr-roundtrip.rs | 2 +- tests/ui/stats/input-stats.stderr | 14 ++-- 36 files changed, 172 insertions(+), 154 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 3e1fff594040e..82a47f3549ebf 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -101,7 +101,7 @@ pub struct Path { } // Succeeds if the path has a single segment that is arg-free and matches the given symbol. -impl PartialEq for Path { +impl PartialEq for Box { #[inline] fn eq(&self, name: &Symbol) -> bool { if let [segment] = self.segments.as_ref() @@ -115,7 +115,7 @@ impl PartialEq for Path { } // Succeeds if the path has segments that are arg-free and match the given symbols. -impl PartialEq<&[Symbol]> for Path { +impl PartialEq<&[Symbol]> for Box { #[inline] fn eq(&self, names: &&[Symbol]) -> bool { self.segments.iter().eq(*names) @@ -134,8 +134,12 @@ impl StableHash for Path { impl Path { /// Convert a span and an identifier to the corresponding /// one-segment path. - pub fn from_ident(ident: Ident) -> Path { - Path { segments: thin_vec![PathSegment::from_ident(ident)], span: ident.span, tokens: None } + pub fn from_ident(ident: Ident) -> Box { + Box::new(Path { + segments: thin_vec![PathSegment::from_ident(ident)], + span: ident.span, + tokens: None, + }) } pub fn is_global(&self) -> bool { @@ -567,7 +571,7 @@ pub struct Crate { #[derive(Clone, Encodable, Decodable, Debug, StableHash)] pub struct MetaItem { pub unsafety: Safety, - pub path: Path, + pub path: Box, pub kind: MetaItemKind, pub span: Span, } @@ -884,10 +888,10 @@ pub enum PatKind { Ident(BindingMode, Ident, Option>), /// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`). - Struct(Option>, Path, ThinVec, PatFieldsRest), + Struct(Option>, Box, ThinVec, PatFieldsRest), /// A tuple struct/variant pattern (`Variant(x, y, .., z)`). - TupleStruct(Option>, Path, ThinVec), + TupleStruct(Option>, Box, ThinVec), /// An or-pattern `A | B | C`. /// Invariant: `pats.len() >= 2`. @@ -897,7 +901,7 @@ pub enum PatKind { /// Unqualified path patterns `A::B::C` can legally refer to variants, structs, constants /// or associated constants. Qualified path patterns `::B::C`/`::B::C` can /// only legally refer to associated constants. - Path(Option>, Path), + Path(Option>, Box), /// A tuple pattern (`(a, b)`). Tuple(ThinVec), @@ -1733,7 +1737,7 @@ pub enum StructRest { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct StructExpr { pub qself: Option>, - pub path: Path, + pub path: Box, pub fields: ThinVec, pub rest: StructRest, } @@ -1850,7 +1854,7 @@ pub enum ExprKind { /// parameters (e.g., `foo::bar::`). /// /// Optionally "qualified" (e.g., ` as SomeTrait>::SomeType`). - Path(Option>, Path), + Path(Option>, Box), /// A referencing operation (`&a`, `&mut a`, `&raw const a` or `&raw mut a`). AddrOf(BorrowKind, Mutability, Box), @@ -1871,6 +1875,7 @@ pub enum ExprKind { OffsetOf(Box, ThinVec), /// A macro invocation; pre-expansion. + // njn: debox all Box? MacCall(Box), /// A struct literal expression. @@ -2043,7 +2048,7 @@ pub enum ClosureBinder { /// is being invoked, and the `args` are arguments passed to it. #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct MacCall { - pub path: Path, + pub path: Box, pub args: Box, } @@ -2122,7 +2127,7 @@ pub struct MacroDef { #[derive(Clone, Encodable, Decodable, Debug, StableHash, Walkable)] pub struct EiiDecl { /// path to the extern item we're targeting - pub foreign_item: Path, + pub foreign_item: Box, pub impl_unsafe: bool, } @@ -2534,7 +2539,7 @@ pub enum TyKind { /// "qualified", e.g., ` as SomeTrait>::SomeType`. /// /// Type parameters are stored in the `Path` itself. - Path(Option>, Path), + Path(Option>, Box), /// A trait object type `Bound1 + Bound2 + Bound3` /// where `Bound` is a trait or a lifetime. TraitObject(#[visitable(extra = BoundKind::TraitObject)] GenericBounds, TraitObjectSyntax), @@ -2683,7 +2688,7 @@ pub enum PreciseCapturingArg { /// Lifetime parameter. Lifetime(#[visitable(extra = LifetimeCtxt::GenericArg)] Lifetime), /// Type or const parameter. - Arg(Path, NodeId), + Arg(Box, NodeId), } /// Inline assembly operand explicit register or register class. @@ -2810,7 +2815,7 @@ impl InlineAsmTemplatePiece { pub struct InlineAsmSym { pub id: NodeId, pub qself: Option>, - pub path: Path, + pub path: Box, } /// Inline assembly operand. @@ -3366,7 +3371,7 @@ pub enum UseTreeKind { /// Used in `use` items both at top-level and inside of braces in import groups. #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct UseTree { - pub prefix: Path, + pub prefix: Box, pub kind: UseTreeKind, } @@ -3464,7 +3469,7 @@ impl NormalAttr { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct AttrItem { pub unsafety: Safety, - pub path: Path, + pub path: Box, pub args: AttrItemKind, // Tokens for the meta item, e.g. just the `foo` within `#[foo]` or `#![foo]`. pub tokens: Option, @@ -3532,7 +3537,7 @@ impl AttrItem { /// same as the impl's `NodeId`). #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct TraitRef { - pub path: Path, + pub path: Box, pub ref_id: NodeId, } @@ -3564,7 +3569,7 @@ pub struct PolyTraitRef { impl PolyTraitRef { pub fn new( generic_params: ThinVec, - path: Path, + path: Box, modifiers: TraitBoundModifiers, span: Span, parens: Parens, @@ -3886,7 +3891,7 @@ pub struct Fn { pub generics: Generics, pub sig: FnSig, pub contract: Option>, - pub define_opaque: Option>, + pub define_opaque: Option)>>, pub body: Option>, /// This function is an implementation of an externally implementable item (EII). @@ -3911,7 +3916,7 @@ impl Fn { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct EiiImpl { pub node_id: NodeId, - pub eii_macro_path: Path, + pub eii_macro_path: Box, /// This field is an implementation detail that prevents a lot of bugs. /// See for an example. /// @@ -3943,7 +3948,7 @@ pub struct Delegation { /// Path resolution id. pub id: NodeId, pub qself: Option>, - pub path: Path, + pub path: Box, pub ident: Ident, pub rename: Option, pub body: Option>, @@ -3967,7 +3972,7 @@ pub enum DelegationSuffixes { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct DelegationMac { pub qself: Option>, - pub prefix: Path, + pub prefix: Box, pub suffixes: DelegationSuffixes, pub body: Option>, } @@ -3979,7 +3984,7 @@ pub struct StaticItem { pub safety: Safety, pub mutability: Mutability, pub expr: Option>, - pub define_opaque: Option>, + pub define_opaque: Option)>>, /// This static is an implementation of an externally implementable item (EII). /// This means, there was an EII declared somewhere and this static is the @@ -3996,7 +4001,7 @@ pub struct ConstItem { pub generics: Generics, pub ty: Box, pub rhs_kind: ConstItemRhsKind, - pub define_opaque: Option>, + pub define_opaque: Option)>>, } #[derive(Clone, Encodable, Decodable, Debug, Walkable)] @@ -4404,7 +4409,7 @@ mod size_asserts { static_assert_size!(ForeignItemKind, 16); static_assert_size!(GenericArg, 24); static_assert_size!(GenericArgs, 40); - static_assert_size!(GenericBound, 88); + static_assert_size!(GenericBound, 72); static_assert_size!(GenericParam, 80); static_assert_size!(Generics, 40); static_assert_size!(Impl, 80); @@ -4413,18 +4418,18 @@ mod size_asserts { static_assert_size!(Lifetime, 16); static_assert_size!(LitKind, 24); static_assert_size!(Local, 96); - static_assert_size!(MetaItem, 88); + static_assert_size!(MetaItem, 72); static_assert_size!(MetaItemKind, 40); static_assert_size!(MetaItemLit, 40); static_assert_size!(Param, 40); - static_assert_size!(Pat, 80); - static_assert_size!(PatKind, 56); + static_assert_size!(Pat, 64); + static_assert_size!(PatKind, 40); static_assert_size!(Path, 24); static_assert_size!(PathSegment, 24); static_assert_size!(QSelf, 24); static_assert_size!(Stmt, 32); static_assert_size!(StmtKind, 16); - static_assert_size!(TraitImplHeader, 72); + static_assert_size!(TraitImplHeader, 56); static_assert_size!(Ty, 64); static_assert_size!(TyKind, 40); // tidy-alphabetical-end diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 88556aa58c773..e9d1c8e2f4d2b 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -515,7 +515,7 @@ impl MetaItem { iter.next(); } let span = span.with_hi(segments.last().unwrap().ident.span.hi()); - Path { span, segments, tokens: None } + Box::new(Path { span, segments, tokens: None }) } Some(TokenTree::Delimited( _span, @@ -741,7 +741,7 @@ fn mk_attr( g: &AttrIdGenerator, style: AttrStyle, unsafety: Safety, - path: Path, + path: Box, args: AttrArgs, span: Span, ) -> Attribute { diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index fb4e76321d150..7f5672ec227cc 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -389,7 +389,7 @@ macro_rules! common_visitor_and_walkers { ThinVec, ThinVec, ThinVec<(Ident, Option)>, - ThinVec<(NodeId, Path)>, + ThinVec<(NodeId, Box)>, ThinVec, ThinVec, ThinVec, diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index c54777d98070a..3c8e63f9652eb 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1902,7 +1902,7 @@ impl<'hir> LoweringContext<'_, 'hir> { pub(super) fn lower_define_opaque( &mut self, hir_id: HirId, - define_opaque: &Option>, + define_opaque: &Option)>>, ) { assert_eq!(self.define_opaque, None); assert!(hir_id.is_owner()); diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 35e16ce78a8a8..c669f645f7bad 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -516,7 +516,7 @@ fn index_ast<'tcx>( // Lacking a better choice, we replace the contents with a macro call. // Unexpanded macros should never reach lowering, so this is not confusing. kind: dummy(Box::new(MacCall { - path: Path { span, segments: thin_vec![], tokens: None }, + path: Box::new(Path { span, segments: thin_vec![], tokens: None }), args: Box::new(DelimArgs { dspan: DelimSpan::from_single(span), delim: Delimiter::Parenthesis, @@ -1462,7 +1462,7 @@ impl<'hir> LoweringContext<'_, 'hir> { &mut self, t: &Ty, qself: &Option>, - path: &Path, + path: &Box, param_mode: ParamMode, itctx: ImplTraitContext, ) -> hir::Ty<'hir> { @@ -2541,7 +2541,7 @@ impl<'hir> LoweringContext<'_, 'hir> { #[instrument(level = "debug", skip(self))] fn lower_const_path_to_const_arg( &mut self, - path: &Path, + path: &Box, res: Res, ty_id: NodeId, span: Span, diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index 8602a21a43487..d6b35e63da87c 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -94,7 +94,7 @@ impl<'a> State<'a> { vis: &ast::Visibility, safety: ast::Safety, defaultness: ast::Defaultness, - define_opaque: Option<&[(ast::NodeId, ast::Path)]>, + define_opaque: Option<&[(ast::NodeId, Box)]>, eii_impls: &[EiiImpl], ) { self.print_define_opaques(define_opaque); @@ -777,7 +777,7 @@ impl<'a> State<'a> { self.hardbreak(); } - fn print_define_opaques(&mut self, define_opaque: Option<&[(ast::NodeId, ast::Path)]>) { + fn print_define_opaques(&mut self, define_opaque: Option<&[(ast::NodeId, Box)]>) { if let Some(define_opaque) = define_opaque { self.word("#[define_opaque("); for (i, (_, path)) in define_opaque.iter().enumerate() { diff --git a/compiler/rustc_attr_parsing/src/parser.rs b/compiler/rustc_attr_parsing/src/parser.rs index 5450a51484542..ef05743639c85 100644 --- a/compiler/rustc_attr_parsing/src/parser.rs +++ b/compiler/rustc_attr_parsing/src/parser.rs @@ -37,7 +37,7 @@ use crate::session_diagnostics::{ #[derive(Clone, Debug)] pub struct PathParser>(pub P); -pub type OwnedPathParser = PathParser; +pub type OwnedPathParser = PathParser>; pub type RefPathParser<'p> = PathParser<&'p Path>; impl> PathParser

{ @@ -678,7 +678,8 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> { negative_sign: expr.span.until(val.span), }); } else if let StmtKind::Expr(expr) = &stmt.kind - && let ExprKind::Path(None, Path { segments, .. }) = &expr.kind + && let ExprKind::Path(None, path) = &expr.kind + && let Path { segments, .. } = &**path && segments.len() == 1 { while let token::Ident(..) | token::Literal(_) | token::Dot = diff --git a/compiler/rustc_builtin_macros/src/assert.rs b/compiler/rustc_builtin_macros/src/assert.rs index 444510ee50572..9103b8409b5c4 100644 --- a/compiler/rustc_builtin_macros/src/assert.rs +++ b/compiler/rustc_builtin_macros/src/assert.rs @@ -34,7 +34,7 @@ pub(crate) fn expand_assert<'cx>( let panic_path = || { if use_panic_2021(span) { // On edition 2021, we always call `$crate::panic::panic_2021!()`. - Path { + Box::new(Path { span: call_site_span, segments: cx .std_path(&[sym::panic, sym::panic_2021]) @@ -42,7 +42,7 @@ pub(crate) fn expand_assert<'cx>( .map(|ident| PathSegment::from_ident(ident)) .collect(), tokens: None, - } + }) } else { // Before edition 2021, we call `panic!()` unqualified, // such that it calls either `std::panic!()` or `core::panic!()`. diff --git a/compiler/rustc_builtin_macros/src/assert/context.rs b/compiler/rustc_builtin_macros/src/assert/context.rs index f15acc154baf3..5c9f01a8dbfbf 100644 --- a/compiler/rustc_builtin_macros/src/assert/context.rs +++ b/compiler/rustc_builtin_macros/src/assert/context.rs @@ -69,7 +69,7 @@ impl<'cx, 'a> Context<'cx, 'a> { /// } /// } /// ``` - pub(super) fn build(mut self, mut cond_expr: Box, panic_path: Path) -> Box { + pub(super) fn build(mut self, mut cond_expr: Box, panic_path: Box) -> Box { let expr_str = pprust::expr_to_string(&cond_expr); self.manage_cond_expr(&mut cond_expr); let initial_imports = self.build_initial_imports(); @@ -142,7 +142,7 @@ impl<'cx, 'a> Context<'cx, 'a> { /// __capture0, /// ... /// ); - fn build_panic(&self, expr_str: &str, panic_path: Path) -> Box { + fn build_panic(&self, expr_str: &str, panic_path: Box) -> Box { let escaped_expr_str = escape_to_fmt(expr_str); let initial = [ TokenTree::token_joint( diff --git a/compiler/rustc_builtin_macros/src/autodiff.rs b/compiler/rustc_builtin_macros/src/autodiff.rs index 311a24280cfb7..7916710d9d53d 100644 --- a/compiler/rustc_builtin_macros/src/autodiff.rs +++ b/compiler/rustc_builtin_macros/src/autodiff.rs @@ -630,7 +630,7 @@ mod llvm_enzyme { thin_vec![segment] }; - let path = Path { span, segments, tokens: None }; + let path = Box::new(Path { span, segments, tokens: None }); ecx.expr_path(path) } diff --git a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs index 80296a43ee490..9e443929a4bc2 100644 --- a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs +++ b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs @@ -356,7 +356,7 @@ fn contains_maybe_sized_bound(bounds: &[GenericBound]) -> bool { bounds.iter().any(is_maybe_sized_bound) } -fn is_sized_marker(path: &ast::Path) -> bool { +fn is_sized_marker(path: &Box) -> bool { const CORE_UNSIZE: [Symbol; 3] = [sym::core, sym::marker, sym::Sized]; const STD_UNSIZE: [Symbol; 3] = [sym::std, sym::marker, sym::Sized]; let segments = || path.segments.iter().map(|segment| segment.ident.name); diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 1577db640502c..bae879974f647 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -1511,7 +1511,8 @@ impl<'a> TraitDef<'a> { fn create_struct_patterns( &self, cx: &ExtCtxt<'_>, - struct_path: ast::Path, + // njn: introduce Path::new()? + struct_path: Box, struct_def: &'a VariantData, prefixes: &[String], by_ref: ByRef, diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs index e7972c5436e13..aaaa1cadcfc29 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs @@ -48,7 +48,7 @@ impl Path { span: Span, self_ty: Ident, self_generics: &Generics, - ) -> ast::Path { + ) -> Box { let mut idents = self.path.iter().map(|s| Ident::new(*s, span)).collect(); let tys = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)); let params = tys.map(GenericArg::Type).collect(); @@ -112,7 +112,7 @@ impl Ty { span: Span, self_ty: Ident, generics: &Generics, - ) -> ast::Path { + ) -> Box { match self { Self_ => { let params: Vec<_> = generics diff --git a/compiler/rustc_builtin_macros/src/edition_panic.rs b/compiler/rustc_builtin_macros/src/edition_panic.rs index 08f555b9e52f6..dc709458a869d 100644 --- a/compiler/rustc_builtin_macros/src/edition_panic.rs +++ b/compiler/rustc_builtin_macros/src/edition_panic.rs @@ -48,7 +48,7 @@ fn expand<'cx>( cx.expr( sp, ExprKind::MacCall(Box::new(MacCall { - path: Path { + path: Box::new(Path { span: sp, segments: cx .std_path(&[sym::panic, mac]) @@ -56,7 +56,7 @@ fn expand<'cx>( .map(|ident| PathSegment::from_ident(ident)) .collect(), tokens: None, - }, + }), args: Box::new(DelimArgs { dspan: DelimSpan::from_single(sp), delim: Delimiter::Parenthesis, diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index e08fb81d4de68..547fea0fcc196 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -38,7 +38,7 @@ struct TestCtxt<'a> { def_site: Span, test_cases: Vec, reexport_test_harness_main: Option, - test_runner: Option, + test_runner: Option>, } /// Traverse the crate, collecting all the test functions, eliding any @@ -229,7 +229,7 @@ fn generate_test_harness( krate: &mut ast::Crate, features: &Features, panic_strategy: PanicStrategy, - test_runner: Option, + test_runner: Option>, ) { let econfig = ExpansionConfig::default(sym::test, features); let ext_cx = ExtCtxt::new(sess, econfig, resolver, None); @@ -391,7 +391,7 @@ fn get_test_name(i: &ast::Item) -> Option { attr::first_attr_value_str_by_name(&i.attrs, sym::rustc_test_marker) } -fn get_test_runner(sess: &Session, krate: &ast::Crate) -> Option { +fn get_test_runner(sess: &Session, krate: &ast::Crate) -> Option> { match AttributeParser::parse_limited(sess, &krate.attrs, &[sym::test_runner]) { Some(rustc_hir::Attribute::Parsed(AttributeKind::TestRunner(path))) => Some(path), _ => None, diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 821f541170f62..736e96ee3adcb 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1072,7 +1072,7 @@ impl SyntaxExtension { pub struct Indeterminate; pub struct DeriveResolution { - pub path: ast::Path, + pub path: Box, pub item: Annotatable, // FIXME: currently this field is only used in `is_none`/`is_some` conditions. However, the // `Arc` will be used if the FIXME in `MacroExpander::fully_expand_fragment` diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 01886a97f55a2..55fb9d9757f61 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -11,13 +11,13 @@ use thin_vec::{ThinVec, thin_vec}; use crate::base::ExtCtxt; impl<'a> ExtCtxt<'a> { - pub fn path(&self, span: Span, strs: Vec) -> ast::Path { + pub fn path(&self, span: Span, strs: Vec) -> Box { self.path_all(span, false, strs, vec![]) } - pub fn path_ident(&self, span: Span, id: Ident) -> ast::Path { + pub fn path_ident(&self, span: Span, id: Ident) -> Box { self.path(span, vec![id]) } - pub fn path_global(&self, span: Span, strs: Vec) -> ast::Path { + pub fn path_global(&self, span: Span, strs: Vec) -> Box { self.path_all(span, true, strs, vec![]) } pub fn path_all( @@ -26,7 +26,7 @@ impl<'a> ExtCtxt<'a> { global: bool, mut idents: Vec, args: Vec, - ) -> ast::Path { + ) -> Box { assert!(!idents.is_empty()); let add_root = global && !idents[0].is_path_segment_keyword(); let mut segments = ThinVec::with_capacity(idents.len() + add_root as usize); @@ -48,13 +48,13 @@ impl<'a> ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, args, }); - ast::Path { span, segments, tokens: None } + Box::new(ast::Path { span, segments, tokens: None }) } pub fn macro_call( &self, span: Span, - path: ast::Path, + path: Box, delim: Delimiter, tokens: TokenStream, ) -> Box { @@ -80,7 +80,7 @@ impl<'a> ExtCtxt<'a> { self.ty(span, ast::TyKind::Infer) } - pub fn ty_path(&self, path: ast::Path) -> Box { + pub fn ty_path(&self, path: Box) -> Box { self.ty(path.span, ast::TyKind::Path(None, path)) } @@ -180,11 +180,16 @@ impl<'a> ExtCtxt<'a> { } } - pub fn trait_ref(&self, path: ast::Path) -> ast::TraitRef { + pub fn trait_ref(&self, path: Box) -> ast::TraitRef { ast::TraitRef { path, ref_id: ast::DUMMY_NODE_ID } } - pub fn poly_trait_ref(&self, span: Span, path: ast::Path, is_const: bool) -> ast::PolyTraitRef { + pub fn poly_trait_ref( + &self, + span: Span, + path: Box, + is_const: bool, + ) -> ast::PolyTraitRef { ast::PolyTraitRef { bound_generic_params: ThinVec::new(), modifiers: ast::TraitBoundModifiers { @@ -202,7 +207,7 @@ impl<'a> ExtCtxt<'a> { } } - pub fn trait_bound(&self, path: ast::Path, is_const: bool) -> ast::GenericBound { + pub fn trait_bound(&self, path: Box, is_const: bool) -> ast::GenericBound { ast::GenericBound::Trait(self.poly_trait_ref(path.span, path, is_const)) } @@ -307,7 +312,7 @@ impl<'a> ExtCtxt<'a> { }) } - pub fn expr_path(&self, path: ast::Path) -> Box { + pub fn expr_path(&self, path: Box) -> Box { self.expr(path.span, ast::ExprKind::Path(None, path)) } @@ -411,7 +416,7 @@ impl<'a> ExtCtxt<'a> { pub fn expr_struct( &self, span: Span, - path: ast::Path, + path: Box, fields: ThinVec, ) -> Box { self.expr( @@ -554,13 +559,13 @@ impl<'a> ExtCtxt<'a> { let pat = PatKind::Ident(ann, ident.with_span_pos(span), None); self.pat(span, pat) } - pub fn pat_path(&self, span: Span, path: ast::Path) -> ast::Pat { + pub fn pat_path(&self, span: Span, path: Box) -> ast::Pat { self.pat(span, PatKind::Path(None, path)) } pub fn pat_tuple_struct( &self, span: Span, - path: ast::Path, + path: Box, subpats: ThinVec, ) -> ast::Pat { self.pat(span, PatKind::TupleStruct(None, path, subpats)) @@ -568,7 +573,7 @@ impl<'a> ExtCtxt<'a> { pub fn pat_struct( &self, span: Span, - path: ast::Path, + path: Box, field_pats: ThinVec, ) -> ast::Pat { self.pat(span, PatKind::Struct(None, path, field_pats, ast::PatFieldsRest::None)) diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 0fd21e017ff61..bea42dee18b8d 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -386,10 +386,10 @@ pub enum InvocationKind { pos: usize, item: Annotatable, /// Required for resolving derive helper attributes. - derives: Vec, + derives: Vec>, }, Derive { - path: ast::Path, + path: Box, is_const: bool, item: Annotatable, }, @@ -2181,7 +2181,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { fn collect_attr( &mut self, - (attr, pos, derives): (ast::Attribute, usize, Vec), + (attr, pos, derives): (ast::Attribute, usize, Vec>), item: Annotatable, kind: AstFragmentKind, ) -> AstFragment { @@ -2203,7 +2203,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { fn take_first_attr( &self, item: &mut impl HasAttrs, - ) -> Option<(ast::Attribute, usize, Vec)> { + ) -> Option<(ast::Attribute, usize, Vec>)> { let mut attr = None; let mut cfg_pos = None; diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index 4044a414c5fee..fcfdc0960c8b3 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -16,7 +16,7 @@ pub(crate) fn placeholder( ) -> AstFragment { fn mac_placeholder() -> Box { Box::new(ast::MacCall { - path: ast::Path { span: DUMMY_SP, segments: ThinVec::new(), tokens: None }, + path: Box::new(ast::Path { span: DUMMY_SP, segments: ThinVec::new(), tokens: None }), args: Box::new(ast::DelimArgs { dspan: ast::tokenstream::DelimSpan::dummy(), delim: Delimiter::Parenthesis, diff --git a/compiler/rustc_expand/src/stats.rs b/compiler/rustc_expand/src/stats.rs index d7bd5329da8b3..dcf28f8aacd7d 100644 --- a/compiler/rustc_expand/src/stats.rs +++ b/compiler/rustc_expand/src/stats.rs @@ -104,7 +104,7 @@ pub(crate) fn update_attr_macro_stats( ecx: &mut ExtCtxt<'_>, fragment_kind: AstFragmentKind, span: Span, - path: &ast::Path, + path: &Box, attr: &ast::Attribute, item: Annotatable, fragment: &AstFragment, diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index 17d00863d99d5..f55a88194d999 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -1684,7 +1684,7 @@ pub enum AttributeKind { }, /// Represents `#![test_runner(path)]` - TestRunner(Path), + TestRunner(Box), /// Represents `#[thread_local]` ThreadLocal, diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 7040fc60e4f1a..81e0ab7fce12e 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -67,7 +67,7 @@ pub(super) fn dummy_arg(ident: Ident, guar: ErrorGuaranteed) -> Param { pub(super) trait RecoverQPath: Sized + 'static { const PATH_STYLE: PathStyle = PathStyle::Expr; fn to_ty(&self) -> Option>; - fn recovered(qself: Option>, path: ast::Path) -> Self; + fn recovered(qself: Option>, path: Box) -> Self; } impl RecoverQPath for Box { @@ -75,7 +75,7 @@ impl RecoverQPath for Box { fn to_ty(&self) -> Option> { T::to_ty(self) } - fn recovered(qself: Option>, path: ast::Path) -> Self { + fn recovered(qself: Option>, path: Box) -> Self { Box::new(T::recovered(qself, path)) } } @@ -85,7 +85,7 @@ impl RecoverQPath for Ty { fn to_ty(&self) -> Option> { Some(Box::new(self.clone())) } - fn recovered(qself: Option>, path: ast::Path) -> Self { + fn recovered(qself: Option>, path: Box) -> Self { Self { span: path.span, kind: TyKind::Path(qself, path), @@ -100,7 +100,7 @@ impl RecoverQPath for Pat { fn to_ty(&self) -> Option> { self.to_ty() } - fn recovered(qself: Option>, path: ast::Path) -> Self { + fn recovered(qself: Option>, path: Box) -> Self { Self { span: path.span, kind: PatKind::Path(qself, path), @@ -114,7 +114,7 @@ impl RecoverQPath for Expr { fn to_ty(&self) -> Option> { self.to_ty() } - fn recovered(qself: Option>, path: ast::Path) -> Self { + fn recovered(qself: Option>, path: Box) -> Self { Self { span: path.span, kind: ExprKind::Path(qself, path), @@ -980,11 +980,11 @@ impl<'a> Parser<'a> { // } debug!(?maybe_struct_name, ?self.token); let mut snapshot = self.create_snapshot_for_diagnostic(); - let path = Path { + let path = Box::new(Path { segments: ThinVec::new(), span: self.prev_token.span.shrink_to_lo(), tokens: None, - }; + }); let struct_expr = snapshot.parse_expr_struct(None, path, false); let block_tail = self.parse_block_tail(lo, s, AttemptLocalParseRecovery::No); return Some(match (struct_expr, block_tail) { @@ -1856,7 +1856,8 @@ impl<'a> Parser<'a> { ) -> PResult<'a, T> { self.expect(exp!(PathSep))?; - let mut path = ast::Path { segments: ThinVec::new(), span: DUMMY_SP, tokens: None }; + let mut path = + Box::new(ast::Path { segments: ThinVec::new(), span: DUMMY_SP, tokens: None }); self.parse_path_segments(&mut path.segments, T::PATH_STYLE, None)?; path.span = ty_span.to(self.prev_token.span); @@ -2815,14 +2816,14 @@ impl<'a> Parser<'a> { PatKind::Ident(_, old_ident, _) => { let path = PatKind::Path( None, - Path { + Box::new(Path { span: new_span, segments: thin_vec![ PathSegment::from_ident(*old_ident), PathSegment::from_ident(*ident), ], tokens: None, - }, + }), ); first_pat = self.mk_pat(new_span, path); show_sugg = true; @@ -2832,7 +2833,11 @@ impl<'a> Parser<'a> { segments.push(PathSegment::from_ident(*ident)); let path = PatKind::Path( old_qself.clone(), - Path { span: new_span, segments, tokens: None }, + Box::new(Path { + span: new_span, + segments, + tokens: None, + }), ); first_pat = self.mk_pat(new_span, path); show_sugg = true; diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index df1877b82cb93..30e516314cac6 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -3758,7 +3758,7 @@ impl<'a> Parser<'a> { fn maybe_parse_struct_expr( &mut self, qself: &Option>, - path: &ast::Path, + path: &Box, ) -> Option>> { let struct_allowed = !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL); match (struct_allowed, self.is_likely_struct_lit()) { @@ -3848,7 +3848,7 @@ impl<'a> Parser<'a> { pub(super) fn parse_struct_fields( &mut self, - pth: ast::Path, + pth: Box, // njn: ref? recover: bool, close: ExpTokenPair, ) -> PResult< @@ -4032,18 +4032,18 @@ impl<'a> Parser<'a> { pub(super) fn parse_expr_struct( &mut self, qself: Option>, - pth: ast::Path, + path: Box, recover: bool, ) -> PResult<'a, Box> { - let lo = pth.span; + let lo = path.span; let (fields, base, recovered_async) = - self.parse_struct_fields(pth.clone(), recover, exp!(CloseBrace))?; + self.parse_struct_fields(path.clone(), recover, exp!(CloseBrace))?; let span = lo.to(self.token.span); self.expect(exp!(CloseBrace))?; let expr = if let Some(guar) = recovered_async { ExprKind::Err(guar) } else { - ExprKind::Struct(Box::new(ast::StructExpr { qself, path: pth, fields, rest: base })) + ExprKind::Struct(Box::new(ast::StructExpr { qself, path, fields, rest: base })) }; Ok(self.mk_expr(span, expr)) } diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 6f5c4c874d83b..fc05e9b21ffda 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1286,7 +1286,7 @@ impl<'a> Parser<'a> { let lo = self.token.span; let mut prefix = - ast::Path { segments: ThinVec::new(), span: lo.shrink_to_lo(), tokens: None }; + Box::new(ast::Path { segments: ThinVec::new(), span: lo.shrink_to_lo(), tokens: None }); let kind = if self.check(exp!(OpenBrace)) || self.check(exp!(Star)) || self.is_import_coupler() { // `use *;` or `use ::*;` or `use {...};` or `use ::{...};` diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 64255d51a7c69..1fc28e756f854 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1509,11 +1509,8 @@ impl<'a> Parser<'a> { self.bump(); // `in` let path = self.parse_path(PathStyle::Mod)?; // `path` self.expect(exp!(CloseParen))?; // `)` - let vis = VisibilityKind::Restricted { - path: Box::new(path), - id: ast::DUMMY_NODE_ID, - shorthand: false, - }; + let vis = + VisibilityKind::Restricted { path, id: ast::DUMMY_NODE_ID, shorthand: false }; return Ok(Visibility { span: lo.to(self.prev_token.span), kind: vis, @@ -1526,11 +1523,8 @@ impl<'a> Parser<'a> { self.bump(); // `(` let path = self.parse_path(PathStyle::Mod)?; // `crate`/`super`/`self` self.expect(exp!(CloseParen))?; // `)` - let vis = VisibilityKind::Restricted { - path: Box::new(path), - id: ast::DUMMY_NODE_ID, - shorthand: true, - }; + let vis = + VisibilityKind::Restricted { path, id: ast::DUMMY_NODE_ID, shorthand: true }; return Ok(Visibility { span: lo.to(self.prev_token.span), kind: vis, @@ -1602,11 +1596,8 @@ impl<'a> Parser<'a> { if self.eat_keyword(exp!(In)) { let path = self.parse_path(PathStyle::Mod)?; // `in path` self.expect(exp!(CloseParen))?; // `)` - let restriction = RestrictionKind::Restricted { - path: Box::new(path), - id: ast::DUMMY_NODE_ID, - shorthand: false, - }; + let restriction = + RestrictionKind::Restricted { path, id: ast::DUMMY_NODE_ID, shorthand: false }; let span = lo.to(self.prev_token.span); Ok((restriction, span, span)) } else if self.look_ahead(1, |t| t == &token::CloseParen) @@ -1614,11 +1605,8 @@ impl<'a> Parser<'a> { { let path = self.parse_path(PathStyle::Mod)?; // `crate`/`super`/`self` self.expect(exp!(CloseParen))?; // `)` - let restriction = RestrictionKind::Restricted { - path: Box::new(path), - id: ast::DUMMY_NODE_ID, - shorthand: true, - }; + let restriction = + RestrictionKind::Restricted { path, id: ast::DUMMY_NODE_ID, shorthand: true }; let span = lo.to(self.prev_token.span); Ok((restriction, span, span)) } else { diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 1b1d7ddb24b1b..19de84a75ccef 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -179,9 +179,9 @@ impl<'a> Parser<'a> { })) } } - NonterminalKind::Path => Ok(ParseNtResult::Path(Box::new( + NonterminalKind::Path => Ok(ParseNtResult::Path( self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?, - ))), + )), NonterminalKind::Meta => { Ok(ParseNtResult::Meta(Box::new(self.parse_attr_item(ForceCollect::Yes)?))) } diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index b66dcddc8d333..5f8c4d2d35a1a 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -1156,7 +1156,7 @@ impl<'a> Parser<'a> { } /// Parse macro invocation - fn parse_pat_mac_invoc(&mut self, path: Path) -> PResult<'a, PatKind> { + fn parse_pat_mac_invoc(&mut self, path: Box) -> PResult<'a, PatKind> { self.bump(); let args = self.parse_delim_args()?; let mac = Box::new(MacCall { path, args }); @@ -1396,7 +1396,11 @@ impl<'a> Parser<'a> { } /// Parse a struct ("record") pattern (e.g. `Foo { ... }` or `Foo::Bar { ... }`). - fn parse_pat_struct(&mut self, qself: Option>, path: Path) -> PResult<'a, PatKind> { + fn parse_pat_struct( + &mut self, + qself: Option>, + path: Box, + ) -> PResult<'a, PatKind> { if qself.is_some() { // Feature gate the use of qualified paths in patterns self.psess.gated_spans.gate(sym::more_qualified_paths, path.span); @@ -1417,7 +1421,7 @@ impl<'a> Parser<'a> { fn parse_pat_tuple_struct( &mut self, qself: Option>, - path: Path, + path: Box, ) -> PResult<'a, PatKind> { let (fields, _) = self.parse_paren_comma_seq(|p| { p.parse_pat_allow_top_guard( diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index ea86c08915b31..33d819f3e7c01 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -77,7 +77,7 @@ impl<'a> Parser<'a> { /// `::a` /// `::F::a` (without disambiguator) /// `::F::a::` (with disambiguator) - pub(super) fn parse_qpath(&mut self, style: PathStyle) -> PResult<'a, (Box, Path)> { + pub(super) fn parse_qpath(&mut self, style: PathStyle) -> PResult<'a, (Box, Box)> { let lo = self.prev_token.span; let ty = self.parse_ty()?; @@ -92,7 +92,7 @@ impl<'a> Parser<'a> { path_span = path_lo.to(self.prev_token.span); } else { path_span = self.token.span.to(self.token.span); - path = ast::Path { segments: ThinVec::new(), span: path_span, tokens: None }; + path = Box::new(ast::Path { segments: ThinVec::new(), span: path_span, tokens: None }); } // See doc comment for `unmatched_angle_bracket_count`. @@ -112,10 +112,9 @@ impl<'a> Parser<'a> { self.parse_path_segments(&mut path.segments, style, None)?; } - Ok(( - qself, - Path { segments: path.segments, span: lo.to(self.prev_token.span), tokens: None }, - )) + path.span = lo.to(self.prev_token.span); + path.tokens = None; + Ok((qself, path)) } /// Recover from an invalid single colon, when the user likely meant a qualified path. @@ -151,7 +150,7 @@ impl<'a> Parser<'a> { true } - pub fn parse_path(&mut self, style: PathStyle) -> PResult<'a, Path> { + pub fn parse_path(&mut self, style: PathStyle) -> PResult<'a, Box> { self.parse_path_inner(style, None) } @@ -169,8 +168,10 @@ impl<'a> Parser<'a> { &mut self, style: PathStyle, ty_generics: Option<&Generics>, - ) -> PResult<'a, Path> { - let reject_generics_if_mod_style = |parser: &Parser<'_>, path: Path| { + ) -> PResult<'a, Box> { + let reject_generics_if_mod_style = |parser: &Parser<'_>, + mut path: Box| + -> Box { // Ensure generic arguments don't end up in attribute paths, such as: // // macro_rules! m { @@ -194,10 +195,9 @@ impl<'a> Parser<'a> { .iter() .map(|segment| PathSegment { ident: segment.ident, id: segment.id, args: None }) .collect(); - Path { segments, ..path } - } else { - path + path.segments = segments; } + path }; if let Some(path) = @@ -221,7 +221,7 @@ impl<'a> Parser<'a> { segments.push(PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt))); } self.parse_path_segments(&mut segments, style, ty_generics)?; - Ok(Path { segments, span: lo.to(self.prev_token.span), tokens: None }) + Ok(Box::new(Path { segments, span: lo.to(self.prev_token.span), tokens: None })) } pub(super) fn parse_path_segments( diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 5bd2ca3139228..1d068ac85883f 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -238,7 +238,12 @@ impl<'a> Parser<'a> { /// Parses a statement macro `mac!(args)` provided a `path` representing `mac`. /// At this point, the `!` token after the path has already been eaten. - fn parse_stmt_mac(&mut self, lo: Span, attrs: AttrVec, path: ast::Path) -> PResult<'a, Stmt> { + fn parse_stmt_mac( + &mut self, + lo: Span, + attrs: AttrVec, + path: Box, + ) -> PResult<'a, Stmt> { let args = self.parse_delim_args()?; let hi = self.prev_token.span; diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 9c873711e2f87..fa367e4f1ec53 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -564,7 +564,7 @@ impl<'a> Parser<'a> { fn parse_remaining_bounds_path( &mut self, generic_params: ThinVec, - path: ast::Path, + path: Box, lo: Span, parse_plus: bool, parens: ast::Parens, @@ -1453,7 +1453,7 @@ impl<'a> Parser<'a> { } // recovers a `Fn(..)` parenthesized-style path from `fn(..)` - fn recover_path_from_fn(&mut self) -> Option { + fn recover_path_from_fn(&mut self) -> Option> { let fn_token_span = self.token.span; self.bump(); let args_lo = self.token.span; @@ -1463,7 +1463,7 @@ impl<'a> Parser<'a> { match self.parse_fn_decl(&mode, AllowPlus::No, RecoverReturnSign::OnlyFatArrow) { Ok(decl) => { self.dcx().emit_err(ExpectedFnPathFoundFnKeyword { fn_token_span }); - Some(ast::Path { + Some(Box::new(ast::Path { span: fn_token_span.to(self.prev_token.span), segments: thin_vec![ast::PathSegment { ident: Ident::new(sym::Fn, fn_token_span), @@ -1478,7 +1478,7 @@ impl<'a> Parser<'a> { ))), }], tokens: None, - }) + })) } Err(diag) => { diag.cancel(); diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index c94f2f3ffb85d..93d4b63a11ccf 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -5596,7 +5596,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } } - fn resolve_define_opaques(&mut self, define_opaque: &Option>) { + fn resolve_define_opaques(&mut self, define_opaque: &Option)>>) { if let Some(define_opaque) = define_opaque { for (id, path) in define_opaque { self.smart_resolve_path(*id, &None, path, PathSource::DefineOpaques); diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 668278f13d9cf..92f65ee50f381 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -4526,7 +4526,11 @@ fn mk_where_bound_predicate( bound_generic_params: ThinVec::new(), modifiers: ast::TraitBoundModifiers::NONE, trait_ref: ast::TraitRef { - path: ast::Path { segments: modified_segments, span: DUMMY_SP, tokens: None }, + path: Box::new(ast::Path { + segments: modified_segments, + span: DUMMY_SP, + tokens: None + }), ref_id: DUMMY_NODE_ID, }, span: DUMMY_SP, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 3b93f2d1fd130..d13dab9e7caad 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -166,7 +166,7 @@ struct ParentScope<'ra> { module: Module<'ra>, expansion: LocalExpnId, macro_rules: MacroRulesScopeRef<'ra>, - derives: &'ra [ast::Path], + derives: &'ra [Box], } impl<'ra> ParentScope<'ra> { @@ -1553,7 +1553,7 @@ pub struct ResolverArenas<'ra> { modules: TypedArena>, imports: TypedArena>, name_resolutions: TypedArena>>, - ast_paths: TypedArena, + ast_paths: TypedArena>, // njn: weird macros: TypedArena>, dropless: DroplessArena, } @@ -1600,7 +1600,7 @@ impl<'ra> ResolverArenas<'ra> { fn alloc_macro_rules_decl(&'ra self, decl: MacroRulesDecl<'ra>) -> &'ra MacroRulesDecl<'ra> { self.dropless.alloc(decl) } - fn alloc_ast_paths(&'ra self, paths: &[ast::Path]) -> &'ra [ast::Path] { + fn alloc_ast_paths(&'ra self, paths: &[Box]) -> &'ra [Box] { self.ast_paths.alloc_from_iter(paths.iter().cloned()) } fn alloc_macro(&'ra self, ext: SyntaxExtension) -> &'ra Arc { diff --git a/src/tools/clippy/clippy_lints/src/visibility.rs b/src/tools/clippy/clippy_lints/src/visibility.rs index 9cefc54598b78..15a648b278d8c 100644 --- a/src/tools/clippy/clippy_lints/src/visibility.rs +++ b/src/tools/clippy/clippy_lints/src/visibility.rs @@ -88,7 +88,7 @@ impl EarlyLintPass for Visibility { if !item.span.in_external_macro(cx.sess().source_map()) && let VisibilityKind::Restricted { path, shorthand, .. } = &item.vis.kind { - if **path == kw::SelfLower && !is_from_proc_macro(cx, item.vis.span) { + if *path == kw::SelfLower && !is_from_proc_macro(cx, item.vis.span) { span_lint_and_then( cx, NEEDLESS_PUB_SELF, @@ -105,7 +105,7 @@ impl EarlyLintPass for Visibility { ); } - if (**path == kw::Super || **path == kw::SelfLower || **path == kw::Crate) + if (*path == kw::Super || *path == kw::SelfLower || *path == kw::Crate) && !*shorthand && let [.., last] = &*path.segments && !is_from_proc_macro(cx, item.vis.span) diff --git a/tests/ui-fulldeps/pprust-expr-roundtrip.rs b/tests/ui-fulldeps/pprust-expr-roundtrip.rs index 84f9a09990fdd..6a4f00b01ee37 100644 --- a/tests/ui-fulldeps/pprust-expr-roundtrip.rs +++ b/tests/ui-fulldeps/pprust-expr-roundtrip.rs @@ -49,7 +49,7 @@ fn expr(kind: ExprKind) -> Box { fn make_x() -> Box { let seg = PathSegment::from_ident(Ident::from_str("x")); - let path = Path { segments: thin_vec![seg], span: DUMMY_SP, tokens: None }; + let path = Box::new(Path { segments: thin_vec![seg], span: DUMMY_SP, tokens: None }); expr(ExprKind::Path(None, path)) } diff --git a/tests/ui/stats/input-stats.stderr b/tests/ui/stats/input-stats.stderr index f4c6808431687..fea431edfae28 100644 --- a/tests/ui/stats/input-stats.stderr +++ b/tests/ui/stats/input-stats.stderr @@ -23,16 +23,16 @@ ast-stats - Path 72 (NN.N%) 1 ast-stats - Struct 72 (NN.N%) 1 ast-stats - Lit 144 (NN.N%) 2 ast-stats - Block 216 (NN.N%) 3 -ast-stats Pat 560 (NN.N%) 7 80 -ast-stats - Struct 80 (NN.N%) 1 -ast-stats - Wild 80 (NN.N%) 1 -ast-stats - Ident 400 (NN.N%) 5 +ast-stats Pat 448 (NN.N%) 7 64 +ast-stats - Struct 64 (NN.N%) 1 +ast-stats - Wild 64 (NN.N%) 1 +ast-stats - Ident 320 (NN.N%) 5 ast-stats GenericParam 400 (NN.N%) 5 80 -ast-stats GenericBound 352 (NN.N%) 4 88 -ast-stats - Trait 352 (NN.N%) 4 ast-stats AssocItem 320 (NN.N%) 4 80 ast-stats - Fn 160 (NN.N%) 2 ast-stats - Type 160 (NN.N%) 2 +ast-stats GenericBound 288 (NN.N%) 4 72 +ast-stats - Trait 288 (NN.N%) 4 ast-stats FieldDef 272 (NN.N%) 2 136 ast-stats Variant 208 (NN.N%) 2 104 ast-stats Block 192 (NN.N%) 6 32 @@ -57,7 +57,7 @@ ast-stats GenericArgs 40 (NN.N%) 1 40 ast-stats - AngleBracketed 40 (NN.N%) 1 ast-stats Crate 40 (NN.N%) 1 40 ast-stats ---------------------------------------------------------------- -ast-stats Total 7_528 127 +ast-stats Total 7_352 127 ast-stats ================================================================ hir-stats ================================================================ hir-stats HIR STATS: input_stats From 059a363db2eede3070fb65c650fd8364c3b9fefc Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Jul 2026 14:58:41 +1000 Subject: [PATCH 5/5] XXX: Box And Expr64! --- 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 | 20 ++++++++++++---- compiler/rustc_resolve/src/late.rs | 2 +- .../clippy/clippy_utils/src/ast_utils/mod.rs | 23 ++++++------------- src/tools/rustfmt/src/expr.rs | 12 +++------- 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 82a47f3549ebf..0a462379dcf7a 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1671,6 +1671,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