diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index bd5ce5d18b839..739f9ee6de390 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -887,11 +887,11 @@ pub enum PatKind { Struct(Option>, Path, ThinVec, PatFieldsRest), /// A tuple struct/variant pattern (`Variant(x, y, .., z)`). - TupleStruct(Option>, Path, ThinVec), + TupleStruct(Option>, Path, ThinVec>), /// An or-pattern `A | B | C`. /// Invariant: `pats.len() >= 2`. - Or(ThinVec), + Or(ThinVec>), /// A possibly qualified path pattern. /// Unqualified path patterns `A::B::C` can legally refer to variants, structs, constants @@ -900,7 +900,7 @@ pub enum PatKind { Path(Option>, Path), /// A tuple pattern (`(a, b)`). - Tuple(ThinVec), + Tuple(ThinVec>), /// A `box` pattern. Box(Box), @@ -918,7 +918,7 @@ pub enum PatKind { Range(Option>, Option>, Spanned), /// A slice pattern `[a, b, c]`. - Slice(ThinVec), + Slice(ThinVec>), /// A rest pattern `..`. /// diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 1e96d1d52f7eb..fafbf68b527fd 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -390,7 +390,7 @@ macro_rules! common_visitor_and_walkers { ThinVec<(NodeId, Path)>, ThinVec, ThinVec, - ThinVec, + ThinVec>, ThinVec>, ThinVec, ThinVec, diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index 8780b70fadfa4..0aea1feda5ca3 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -159,7 +159,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_pat_tuple( &mut self, - pats: &[Pat], + pats: &[Box], ctx: &str, ) -> (&'hir [hir::Pat<'hir>], hir::DotDotPos) { let mut elems = Vec::with_capacity(pats.len()); @@ -214,7 +214,7 @@ impl<'hir> LoweringContext<'_, 'hir> { /// When encountering `($binding_mode $ident @)? ..` (`slice`), /// this is interpreted as a sub-slice pattern semantically. /// Patterns that follow, which are not like `slice` -- or an error occurs, are in `after`. - fn lower_pat_slice(&mut self, pats: &[Pat]) -> hir::PatKind<'hir> { + fn lower_pat_slice(&mut self, pats: &[Box]) -> hir::PatKind<'hir> { let mut before = Vec::new(); let mut after = Vec::new(); let mut slice = None; diff --git a/compiler/rustc_builtin_macros/src/autodiff.rs b/compiler/rustc_builtin_macros/src/autodiff.rs index 311a24280cfb7..9555903580004 100644 --- a/compiler/rustc_builtin_macros/src/autodiff.rs +++ b/compiler/rustc_builtin_macros/src/autodiff.rs @@ -533,7 +533,7 @@ mod llvm_enzyme { ast::Param { attrs: ast::AttrVec::new(), ty, - pat: Box::new(ecx.pat_wild(span)), + pat: ecx.pat_wild(span), id: ast::DUMMY_NODE_ID, span, is_placeholder: false, diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index ff6b15b173ed1..4401f0771fe14 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -1515,7 +1515,7 @@ impl<'a> TraitDef<'a> { struct_def: &'a VariantData, prefixes: &[String], by_ref: ByRef, - ) -> ThinVec { + ) -> ThinVec> { prefixes .iter() .map(|prefix| { @@ -1551,7 +1551,7 @@ impl<'a> TraitDef<'a> { attrs: ast::AttrVec::new(), id: ast::DUMMY_NODE_ID, span: pat.span.with_ctxt(self.span.ctxt()), - pat: Box::new(pat), + pat, is_placeholder: false, } }) diff --git a/compiler/rustc_builtin_macros/src/offload.rs b/compiler/rustc_builtin_macros/src/offload.rs index d20c07f8619dc..cfb248180a0b3 100644 --- a/compiler/rustc_builtin_macros/src/offload.rs +++ b/compiler/rustc_builtin_macros/src/offload.rs @@ -165,7 +165,7 @@ pub(crate) fn expand_kernel( }); for param in host_fn.sig.decl.inputs.iter_mut() { - param.pat = Box::new(ecx.pat_wild(param.pat.span)); + param.pat = ecx.pat_wild(param.pat.span); } // inline(never) attr diff --git a/compiler/rustc_builtin_macros/src/pattern_type.rs b/compiler/rustc_builtin_macros/src/pattern_type.rs index 53ab3fcd9b34b..622a16d2d9acf 100644 --- a/compiler/rustc_builtin_macros/src/pattern_type.rs +++ b/compiler/rustc_builtin_macros/src/pattern_type.rs @@ -57,7 +57,7 @@ fn ty_pat(kind: TyPatKind, span: Span) -> TyPat { TyPat { id: DUMMY_NODE_ID, kind, span, tokens: None } } -fn pat_to_ty_pat(cx: &mut ExtCtxt<'_>, pat: ast::Pat) -> TyPat { +fn pat_to_ty_pat(cx: &mut ExtCtxt<'_>, pat: Box) -> TyPat { let kind = match pat.kind { ast::PatKind::Range(start, end, include_end) => TyPatKind::Range( start.map(|value| { @@ -80,7 +80,7 @@ fn pat_to_ty_pat(cx: &mut ExtCtxt<'_>, pat: ast::Pat) -> TyPat { TyPatKind::Or(variants.into_iter().map(|pat| pat_to_ty_pat(cx, pat)).collect()) } ast::PatKind::Err(guar) => TyPatKind::Err(guar), - ast::PatKind::Paren(p) => pat_to_ty_pat(cx, *p).kind, + ast::PatKind::Paren(p) => pat_to_ty_pat(cx, p).kind, _ => TyPatKind::Err(cx.dcx().span_err(pat.span, "pattern not supported in pattern types")), }; ty_pat(kind, pat.span) diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 01886a97f55a2..28bc3da46761f 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -237,7 +237,7 @@ impl<'a> ExtCtxt<'a> { }; let local = Box::new(ast::Local { super_: None, - pat: Box::new(pat), + pat, ty, id: ast::DUMMY_NODE_ID, kind: LocalKind::Init(ex), @@ -253,7 +253,7 @@ impl<'a> ExtCtxt<'a> { pub fn stmt_let_type_only(&self, span: Span, ty: Box) -> ast::Stmt { let local = Box::new(ast::Local { super_: None, - pat: Box::new(self.pat_wild(span)), + pat: self.pat_wild(span), ty: Some(ty), id: ast::DUMMY_NODE_ID, kind: LocalKind::Decl, @@ -532,16 +532,16 @@ impl<'a> ExtCtxt<'a> { self.expr_match(sp, head, thin_vec![ok_arm, err_arm]) } - pub fn pat(&self, span: Span, kind: PatKind) -> ast::Pat { - ast::Pat { id: ast::DUMMY_NODE_ID, kind, span, tokens: None } + pub fn pat(&self, span: Span, kind: PatKind) -> Box { + Box::new(ast::Pat { id: ast::DUMMY_NODE_ID, kind, span, tokens: None }) } - pub fn pat_wild(&self, span: Span) -> ast::Pat { + pub fn pat_wild(&self, span: Span) -> Box { self.pat(span, PatKind::Wild) } - pub fn pat_lit(&self, span: Span, expr: Box) -> ast::Pat { + pub fn pat_lit(&self, span: Span, expr: Box) -> Box { self.pat(span, PatKind::Expr(expr)) } - pub fn pat_ident(&self, span: Span, ident: Ident) -> ast::Pat { + pub fn pat_ident(&self, span: Span, ident: Ident) -> Box { self.pat_ident_binding_mode(span, ident, ast::BindingMode::NONE) } @@ -550,19 +550,19 @@ impl<'a> ExtCtxt<'a> { span: Span, ident: Ident, ann: ast::BindingMode, - ) -> ast::Pat { + ) -> Box { 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: ast::Path) -> Box { self.pat(span, PatKind::Path(None, path)) } pub fn pat_tuple_struct( &self, span: Span, path: ast::Path, - subpats: ThinVec, - ) -> ast::Pat { + subpats: ThinVec>, + ) -> Box { self.pat(span, PatKind::TupleStruct(None, path, subpats)) } pub fn pat_struct( @@ -570,23 +570,23 @@ impl<'a> ExtCtxt<'a> { span: Span, path: ast::Path, field_pats: ThinVec, - ) -> ast::Pat { + ) -> Box { self.pat(span, PatKind::Struct(None, path, field_pats, ast::PatFieldsRest::None)) } - pub fn pat_tuple(&self, span: Span, pats: ThinVec) -> ast::Pat { + pub fn pat_tuple(&self, span: Span, pats: ThinVec>) -> Box { self.pat(span, PatKind::Tuple(pats)) } - pub fn pat_some(&self, span: Span, pat: ast::Pat) -> ast::Pat { + pub fn pat_some(&self, span: Span, pat: Box) -> Box { let some = self.std_path(&[sym::option, sym::Option, sym::Some]); let path = self.path_global(span, some); self.pat_tuple_struct(span, path, thin_vec![pat]) } - pub fn arm(&self, span: Span, pat: ast::Pat, expr: Box) -> ast::Arm { + pub fn arm(&self, span: Span, pat: Box, expr: Box) -> ast::Arm { ast::Arm { attrs: AttrVec::new(), - pat: Box::new(pat), + pat, guard: None, body: Some(expr), span, @@ -665,11 +665,10 @@ impl<'a> ExtCtxt<'a> { } pub fn param(&self, span: Span, ident: Ident, ty: Box) -> ast::Param { - let pat = Box::new(self.pat_ident(span, ident)); ast::Param { attrs: AttrVec::default(), id: ast::DUMMY_NODE_ID, - pat, + pat: self.pat_ident(span, ident), span, ty, is_placeholder: false, diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 0fd21e017ff61..74acb329730a0 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1160,12 +1160,12 @@ pub fn parse_ast_fragment<'a>( } } AstFragmentKind::Ty => AstFragment::Ty(this.parse_ty()?), - AstFragmentKind::Pat => AstFragment::Pat(Box::new(this.parse_pat_allow_top_guard( + AstFragmentKind::Pat => AstFragment::Pat(this.parse_pat_allow_top_guard( None, RecoverComma::No, RecoverColon::Yes, CommaRecoveryMode::LikelyTuple, - )?)), + )?), AstFragmentKind::Crate => AstFragment::Crate(this.parse_crate_mod()?), AstFragmentKind::Arms | AstFragmentKind::ExprFields diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 7040fc60e4f1a..a3aecd7840fdb 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -2756,9 +2756,9 @@ impl<'a> Parser<'a> { #[cold] pub(crate) fn recover_colon_colon_in_pat_typo( &mut self, - mut first_pat: Pat, + mut first_pat: Box, expected: Option, - ) -> Pat { + ) -> Box { if token::Colon != self.token.kind { return first_pat; } diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 60a94345c5325..af409ad782eed 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2651,7 +2651,7 @@ impl<'a> Parser<'a> { let lo = self.token.span; let attrs = self.parse_outer_attributes()?; self.collect_tokens(None, attrs, ForceCollect::No, |this, attrs| { - let pat = Box::new(this.parse_pat_no_top_alt(Some(Expected::ParameterName), None)?); + let pat = this.parse_pat_no_top_alt(Some(Expected::ParameterName), None)?; let ty = if this.eat(exp!(Colon)) { this.parse_ty()? } else { @@ -2849,7 +2849,7 @@ impl<'a> Parser<'a> { let (expr, _) = self.parse_expr_assoc_with(Bound::Excluded(prec_let_scrutinee_needs_par()), attrs)?; let span = lo.to(expr.span); - Ok(self.mk_expr(span, ExprKind::Let(Box::new(pat), expr, span, recovered))) + Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span, recovered))) } /// Parses an `else { ... }` expression (`else` token already eaten). @@ -2965,7 +2965,7 @@ impl<'a> Parser<'a> { } // Public to use it for custom `for` expressions in rustfmt forks like https://github.com/tucant/rustfmt - pub fn parse_for_head(&mut self) -> PResult<'a, (Pat, Box)> { + pub fn parse_for_head(&mut self) -> PResult<'a, (Box, Box)> { let begin_paren = if self.token == token::OpenParen { // Record whether we are about to parse `for (`. // This is used below for recovery in case of `for ( $stuff ) $block` @@ -3042,7 +3042,6 @@ impl<'a> Parser<'a> { let kind = if is_await { ForLoopKind::ForAwait } else { ForLoopKind::For }; let (pat, expr) = self.parse_for_head()?; - let pat = Box::new(pat); // Recover from missing expression in `for` loop if matches!(expr.kind, ExprKind::Block(..)) && self.token.kind != token::OpenBrace @@ -3234,7 +3233,7 @@ impl<'a> Parser<'a> { // Always push at least one arm to make the match non-empty arms.push(Arm { attrs: Default::default(), - pat: Box::new(self.mk_pat(span, ast::PatKind::Err(guar))), + pat: self.mk_pat(span, ast::PatKind::Err(guar)), guard: None, body: Some(self.mk_expr_err(span, guar)), span, @@ -3339,7 +3338,6 @@ impl<'a> Parser<'a> { self.collect_tokens(None, attrs, ForceCollect::No, |this, attrs| { let lo = this.token.span; let (pat, guard) = this.parse_match_arm_pat_and_guard()?; - let pat = Box::new(pat); let span_before_body = this.prev_token.span; let arm_body; @@ -3576,7 +3574,7 @@ impl<'a> Parser<'a> { Ok(Box::new(guard)) } - fn parse_match_arm_pat_and_guard(&mut self) -> PResult<'a, (Pat, Option>)> { + fn parse_match_arm_pat_and_guard(&mut self) -> PResult<'a, (Box, Option>)> { if self.token == token::OpenParen { let left = self.token.span; let pat = self.parse_pat_no_top_guard( diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 16fed9c6c273b..2651c7893bba7 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -3455,7 +3455,7 @@ impl<'a> Parser<'a> { match ty { Ok(ty) => { let pat = this.mk_pat(ty.span, PatKind::Missing); - (Box::new(pat), ty) + (pat, ty) } // If this is a C-variadic argument and we hit an error, return the error. Err(err) if this.token == token::DotDotDot => return Err(err), diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 1b1d7ddb24b1b..0c457e9321123 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -151,8 +151,7 @@ impl<'a> Parser<'a> { RecoverColon::No, CommaRecoveryMode::EitherTupleOrPipe, ), - }) - .map(Box::new)?, + })?, pat_kind, )), NonterminalKind::Expr(expr_kind) => { diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index b66dcddc8d333..a42ef94067568 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -107,7 +107,7 @@ impl<'a> Parser<'a> { rc: RecoverComma, ra: RecoverColon, rt: CommaRecoveryMode, - ) -> PResult<'a, Pat> { + ) -> PResult<'a, Box> { let pat = self.parse_pat_no_top_guard(expected, rc, ra, rt)?; if self.eat_keyword(exp!(If)) { @@ -123,7 +123,7 @@ impl<'a> Parser<'a> { // Feature-gate guard patterns self.psess.gated_spans.gate(sym::guard_patterns, guard.span()); let span = pat.span.to(guard.span()); - Ok(self.mk_pat(span, PatKind::Guard(Box::new(pat), guard))) + Ok(self.mk_pat(span, PatKind::Guard(pat, guard))) } else { Ok(pat) } @@ -138,7 +138,7 @@ impl<'a> Parser<'a> { &mut self, expected: Option, syntax_loc: Option, - ) -> PResult<'a, Pat> { + ) -> PResult<'a, Box> { self.parse_pat_with_range_pat(true, expected, syntax_loc) } @@ -157,12 +157,13 @@ impl<'a> Parser<'a> { rc: RecoverComma, ra: RecoverColon, rt: CommaRecoveryMode, - ) -> PResult<'a, Pat> { + ) -> PResult<'a, Box> { self.parse_pat_no_top_guard_inner(expected, rc, ra, rt, None).map(|(pat, _)| pat) } /// Returns the pattern and a bool indicating whether we recovered from a trailing vert (true = /// recovered). + // njn: return Box? fn parse_pat_no_top_guard_inner( &mut self, expected: Option, @@ -170,7 +171,7 @@ impl<'a> Parser<'a> { ra: RecoverColon, rt: CommaRecoveryMode, syntax_loc: Option, - ) -> PResult<'a, (Pat, bool)> { + ) -> PResult<'a, (Box, bool)> { // Keep track of whether we recovered from a trailing vert so that we can avoid duplicated // suggestions (which bothers rustfix). // @@ -182,6 +183,7 @@ impl<'a> Parser<'a> { }; // Parse the first pattern (`p_0`). + // njn: return Box here? let mut first_pat = match self.parse_pat_no_top_alt(expected, syntax_loc) { Ok(pat) => pat, Err(err) @@ -271,7 +273,6 @@ impl<'a> Parser<'a> { CommaRecoveryMode::LikelyTuple, Some(syntax_loc), )?; - let pat = Box::new(pat); let colon = self.eat(exp!(Colon)); if let PatKind::Or(pats) = &pat.kind { @@ -694,7 +695,7 @@ impl<'a> Parser<'a> { PatVisitor { parser: self, stmt, arm: None, field: None }.visit_stmt(stmt); } - fn eat_metavar_pat(&mut self) -> Option { + fn eat_metavar_pat(&mut self) -> Option> { // Must try both kinds of pattern nonterminals. if let Some(pat) = self.eat_metavar_seq_with_matcher( |mv_kind| matches!(mv_kind, MetaVarKind::Pat(PatParam { .. })), @@ -722,7 +723,7 @@ impl<'a> Parser<'a> { allow_range_pat: bool, expected: Option, syntax_loc: Option, - ) -> PResult<'a, Pat> { + ) -> PResult<'a, Box> { maybe_recover_from_interpolated_ty_qpath!(self, true); if let Some(pat) = self.eat_metavar_pat() { @@ -936,7 +937,7 @@ impl<'a> Parser<'a> { /// /// [and]: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/pattern-matching #[cold] - fn recover_intersection_pat(&mut self, lhs: Pat) -> PResult<'a, Pat> { + fn recover_intersection_pat(&mut self, lhs: Box) -> PResult<'a, Box> { let mut rhs = self.parse_pat_no_top_alt(None, None)?; let whole_span = lhs.span.to(rhs.span); @@ -945,7 +946,7 @@ impl<'a> Parser<'a> { let lhs_span = lhs.span; // Move the LHS into the RHS as a subpattern. // The RHS is now the full pattern. - *sub = Some(Box::new(lhs)); + *sub = Some(lhs); self.dcx().emit_err(PatternOnWrongSideOfAt { whole_span, @@ -1002,7 +1003,7 @@ impl<'a> Parser<'a> { let (pinned, mutbl) = self.parse_pin_and_mut(); let subpat = self.parse_pat_with_range_pat(false, expected, None)?; - Ok(PatKind::Ref(Box::new(subpat), pinned, mutbl)) + Ok(PatKind::Ref(subpat, pinned, mutbl)) } /// Parse a tuple or parenthesis pattern. @@ -1060,7 +1061,7 @@ impl<'a> Parser<'a> { } // (pat) with optional parentheses - _ => PatKind::Paren(Box::new(pat)), + _ => PatKind::Paren(pat), } } else { PatKind::Tuple(fields) @@ -1167,7 +1168,7 @@ impl<'a> Parser<'a> { &mut self, err: Diag<'a>, expected: Option, - ) -> PResult<'a, Pat> { + ) -> PResult<'a, Box> { err.cancel(); let expected = Expected::to_string_or_fallback(expected); @@ -1366,7 +1367,7 @@ impl<'a> Parser<'a> { } let sub = if self.eat(exp!(At)) { - Some(Box::new(self.parse_pat_no_top_alt(Some(Expected::BindingPattern), None)?)) + Some(self.parse_pat_no_top_alt(Some(Expected::BindingPattern), None)?) } else { None }; @@ -1455,14 +1456,12 @@ impl<'a> Parser<'a> { self.parse_builtin(|self_, _lo, ident| { Ok(match ident.name { // builtin#deref(PAT) - sym::deref => { - Some(ast::PatKind::Deref(Box::new(self_.parse_pat_allow_top_guard( - None, - RecoverComma::Yes, - RecoverColon::Yes, - CommaRecoveryMode::LikelyTuple, - )?))) - } + sym::deref => Some(ast::PatKind::Deref(self_.parse_pat_allow_top_guard( + None, + RecoverComma::Yes, + RecoverColon::Yes, + CommaRecoveryMode::LikelyTuple, + )?)), _ => None, }) }) @@ -1484,14 +1483,14 @@ impl<'a> Parser<'a> { // We cannot use `parse_pat_ident()` since it will complain `box` // is not an identifier. let sub = if self.eat(exp!(At)) { - Some(Box::new(self.parse_pat_no_top_alt(Some(Expected::BindingPattern), None)?)) + Some(self.parse_pat_no_top_alt(Some(Expected::BindingPattern), None)?) } else { None }; Ok(PatKind::Ident(BindingMode::NONE, Ident::new(kw::Box, box_span), sub)) } else { - let pat = Box::new(self.parse_pat_with_range_pat(false, None, None)?); + let pat = self.parse_pat_with_range_pat(false, None, None)?; self.psess.gated_spans.gate(sym::box_patterns, box_span.to(self.prev_token.span)); Ok(PatKind::Box(pat)) } @@ -1761,17 +1760,14 @@ impl<'a> Parser<'a> { ) { self.psess.gated_spans.gate(sym::mut_ref, fieldpat.span); } - let subpat = if is_box { - self.mk_pat(lo.to(hi), PatKind::Box(Box::new(fieldpat))) - } else { - fieldpat - }; + let subpat = + if is_box { self.mk_pat(lo.to(hi), PatKind::Box(fieldpat)) } else { fieldpat }; (subpat, fieldname, true) }; Ok(PatField { ident: fieldname, - pat: Box::new(subpat), + pat: subpat, is_shorthand, attrs, id: ast::DUMMY_NODE_ID, @@ -1780,11 +1776,11 @@ impl<'a> Parser<'a> { }) } - pub(super) fn mk_pat_ident(&self, span: Span, ann: BindingMode, ident: Ident) -> Pat { + pub(super) fn mk_pat_ident(&self, span: Span, ann: BindingMode, ident: Ident) -> Box { self.mk_pat(span, PatKind::Ident(ann, ident, None)) } - pub(super) fn mk_pat(&self, span: Span, kind: PatKind) -> Pat { - Pat { kind, span, id: ast::DUMMY_NODE_ID, tokens: None } + pub(super) fn mk_pat(&self, span: Span, kind: PatKind) -> Box { + Box::new(Pat { kind, span, id: ast::DUMMY_NODE_ID, tokens: None }) } } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index c94f2f3ffb85d..7cc8b55331651 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -4103,7 +4103,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { /// pattern as a whole counts as a never pattern (since it's definitionallly unreachable). fn compute_and_check_or_pat_binding_map( &mut self, - pats: &[Pat], + pats: &[Box], ) -> Result, IsNeverPattern> { let mut missing_vars = FxIndexMap::default(); let mut inconsistent_vars = FxIndexMap::default(); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 3b93f2d1fd130..1d4a6ddb18a0f 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -229,8 +229,8 @@ enum Used { #[derive(Debug)] struct BindingError { name: Ident, - origin: Vec<(Span, ast::Pat)>, - target: Vec, + origin: Vec<(Span, Box)>, + target: Vec>, could_be_path: bool, } diff --git a/src/tools/clippy/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs b/src/tools/clippy/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs index 897d720036ee9..a88990e94ab77 100644 --- a/src/tools/clippy/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs +++ b/src/tools/clippy/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs @@ -8,7 +8,7 @@ use super::UNNEEDED_WILDCARD_PATTERN; pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) { if let PatKind::TupleStruct(_, _, ref patterns) | PatKind::Tuple(ref patterns) = pat.kind - && let Some(rest_index) = patterns.iter().position(Pat::is_rest) + && let Some(rest_index) = patterns.iter().position(|pat| pat.is_rest()) { if let Some((left_index, left_pat)) = patterns[..rest_index] .iter() diff --git a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs index d1096a02fd634..24cde7ec503f7 100644 --- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs +++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs @@ -161,7 +161,7 @@ fn insert_necessary_parens(pat: &mut Pat) { Ref(p, Pinnedness::Not, Mutability::Not) if matches!(p.kind, Ident(BindingMode::MUT, ..)) => p, _ => return, }; - target.kind = Paren(Box::new(take_pat(target))); + target.kind = Paren(take_pat(target)); } } Visitor.visit_pat(pat); @@ -229,7 +229,7 @@ macro_rules! always_pat { /// Focus on `focus_idx` in `alternatives`, /// attempting to extend it with elements of the same constructor `C` /// in `alternatives[focus_idx + 1..]`. -fn transform_with_focus_on_idx(alternatives: &mut ThinVec, focus_idx: usize) -> bool { +fn transform_with_focus_on_idx(alternatives: &mut ThinVec>, focus_idx: usize) -> bool { // Extract the kind; we'll need to make some changes in it. let mut focus_kind = mem::replace(&mut alternatives[focus_idx].kind, Wild); // We'll focus on `alternatives[focus_idx]`, @@ -258,20 +258,20 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec, focus_idx: usize Box(target) => extend_with_matching( target, start, alternatives, |k| matches!(k, Box(_)), - |k| always_pat!(k, Box(p) => *p), + |k| always_pat!(k, Box(p) => p), ), // Transform `&mut x | ... | &mut y` into `&mut (x | y)`. Ref(target, _, Mutability::Mut) => extend_with_matching( target, start, alternatives, |k| matches!(k, Ref(_, _, Mutability::Mut)), - |k| always_pat!(k, Ref(p, _, _) => *p), + |k| always_pat!(k, Ref(p, _, _) => p), ), // Transform `b @ p0 | ... b @ p1` into `b @ (p0 | p1)`. Ident(b1, i1, Some(target)) => extend_with_matching( target, start, alternatives, // Binding names must match. |k| matches!(k, Ident(b2, i2, Some(_)) if b1 == b2 && eq_id(*i1, *i2)), - |k| always_pat!(k, Ident(_, _, Some(p)) => *p), + |k| always_pat!(k, Ident(_, _, Some(p)) => p), ), // Transform `[pre, x, post] | ... | [pre, y, post]` into `[pre, x | y, post]`. Slice(ps1) => extend_with_matching_product( @@ -316,7 +316,7 @@ fn extend_with_struct_pat( fps1: &mut [ast::PatField], rest1: ast::PatFieldsRest, start: usize, - alternatives: &mut ThinVec, + alternatives: &mut ThinVec>, ) -> bool { (0..fps1.len()).any(|idx| { let pos_in_2 = Cell::new(None); // The element `k`. @@ -346,7 +346,7 @@ fn extend_with_struct_pat( })) }, // Extract `p2_k`. - |k| always_pat!(k, Struct(_, _, mut fps, _) => *fps.swap_remove(pos_in_2.take().unwrap()).pat), + |k| always_pat!(k, Struct(_, _, mut fps, _) => fps.swap_remove(pos_in_2.take().unwrap()).pat), ); extend_with_tail_or(&mut fps1[idx].pat, tail_or) }) @@ -358,11 +358,11 @@ fn extend_with_struct_pat( /// while also requiring `ps1[..n] ~ ps2[..n]` (pre) and `ps1[n + 1..] ~ ps2[n + 1..]` (post), /// where `~` denotes semantic equality. fn extend_with_matching_product( - targets: &mut [Pat], + targets: &mut [Box], start: usize, - alternatives: &mut ThinVec, - predicate: impl Fn(&PatKind, &[Pat], usize) -> bool, - extract: impl Fn(PatKind) -> ThinVec, + alternatives: &mut ThinVec>, + predicate: impl Fn(&PatKind, &[Box], usize) -> bool, + extract: impl Fn(PatKind) -> ThinVec>, ) -> bool { (0..targets.len()).any(|idx| { let tail_or = drain_matching( @@ -377,20 +377,20 @@ fn extend_with_matching_product( /// Extract the pattern from the given one and replace it with `Wild`. /// This is meant for temporarily swapping out the pattern for manipulation. -fn take_pat(from: &mut Pat) -> Pat { - let dummy = Pat { +fn take_pat(from: &mut Box) -> Box { + let dummy = Box::new(Pat { id: DUMMY_NODE_ID, kind: Wild, span: DUMMY_SP, tokens: None, - }; + }); mem::replace(from, dummy) } /// Extend `target` as an or-pattern with the alternatives /// in `tail_or` if there are any and return if there were. -fn extend_with_tail_or(target: &mut Pat, tail_or: ThinVec) -> bool { - fn extend(target: &mut Pat, mut tail_or: ThinVec) { +fn extend_with_tail_or(target: &mut Box, tail_or: ThinVec>) -> bool { + fn extend(target: &mut Box, mut tail_or: ThinVec>) { // On an existing or-pattern in the target, append to it, // otherwise convert the target to an or-pattern. if let Or(ps) = &mut target.kind { @@ -414,10 +414,10 @@ fn extend_with_tail_or(target: &mut Pat, tail_or: ThinVec) -> bool { // Only elements beginning with `start` are considered for extraction. fn drain_matching( start: usize, - alternatives: &mut ThinVec, + alternatives: &mut ThinVec>, predicate: impl Fn(&PatKind) -> bool, - extract: impl Fn(PatKind) -> Pat, -) -> ThinVec { + extract: impl Fn(PatKind) -> Box, +) -> ThinVec> { let mut tail_or = ThinVec::new(); let mut idx = 0; @@ -433,19 +433,19 @@ fn drain_matching( } fn extend_with_matching( - target: &mut Pat, + target: &mut Box, start: usize, - alternatives: &mut ThinVec, + alternatives: &mut ThinVec>, predicate: impl Fn(&PatKind) -> bool, - extract: impl Fn(PatKind) -> Pat, + extract: impl Fn(PatKind) -> Box, ) -> bool { extend_with_tail_or(target, drain_matching(start, alternatives, predicate, extract)) } /// Are the patterns in `ps1` and `ps2` equal save for `ps1[idx]` compared to `ps2[idx]`? -fn eq_pre_post(ps1: &[Pat], ps2: &[Pat], idx: usize) -> bool { +fn eq_pre_post(ps1: &[Box], ps2: &[Box], idx: usize) -> bool { ps1.len() == ps2.len() && ps1[idx].is_rest() == ps2[idx].is_rest() // Avoid `[x, ..] | [x, 0]` => `[x, .. | 0]`. - && over(&ps1[..idx], &ps2[..idx], eq_pat) - && over(&ps1[idx + 1..], &ps2[idx + 1..], eq_pat) + && over(&ps1[..idx], &ps2[..idx], |l, r| eq_pat(l, r)) + && over(&ps1[idx + 1..], &ps2[idx + 1..], |l, r| eq_pat(l, r)) } diff --git a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs index fa93cf208c9d9..88ff2bac6fec5 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs @@ -48,10 +48,10 @@ pub fn eq_pat(l: &Pat, r: &Pat) -> bool { }, (Box(l), Box(r)) => eq_pat(l, r), (Ref(l, l_pin, l_mut), Ref(r, r_pin, r_mut)) => l_pin == r_pin && l_mut == r_mut && eq_pat(l, r), - (Tuple(l), Tuple(r)) | (Slice(l), Slice(r)) => over(l, r, eq_pat), + (Tuple(l), Tuple(r)) | (Slice(l), Slice(r)) => over(l, r, |l, r| eq_pat(l, r)), (Path(lq, lp), Path(rq, rp)) => both(lq.as_deref(), rq.as_deref(), eq_qself) && eq_path(lp, rp), (TupleStruct(lqself, lp, lfs), TupleStruct(rqself, rp, rfs)) => { - eq_maybe_qself(lqself.as_deref(), rqself.as_deref()) && eq_path(lp, rp) && over(lfs, rfs, eq_pat) + eq_maybe_qself(lqself.as_deref(), rqself.as_deref()) && eq_path(lp, rp) && over(lfs, rfs, |l, r| eq_pat(l, r)) }, (Struct(lqself, lp, lfs, lr), Struct(rqself, rp, rfs, rr)) => { lr == rr @@ -59,7 +59,7 @@ pub fn eq_pat(l: &Pat, r: &Pat) -> bool { && eq_path(lp, rp) && unordered_over(lfs, rfs, eq_field_pat) }, - (Or(ls), Or(rs)) => unordered_over(ls, rs, eq_pat), + (Or(ls), Or(rs)) => unordered_over(ls, rs, |l, r| eq_pat(l, r)), (MacCall(l), MacCall(r)) => eq_mac_call(l, r), _ => false, } diff --git a/src/tools/rustfmt/src/parse/macros/mod.rs b/src/tools/rustfmt/src/parse/macros/mod.rs index 00e0f6f58bd37..8e9d071aceeed 100644 --- a/src/tools/rustfmt/src/parse/macros/mod.rs +++ b/src/tools/rustfmt/src/parse/macros/mod.rs @@ -61,7 +61,7 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option { Pat, NonterminalKind::Pat(PatParam { inferred: false }), |parser: &mut Parser<'b>| parser.parse_pat_no_top_alt(None, None), - |x: ast::Pat| Some(Box::new(x)) + |x: Box| Some(x) ); // `parse_item` returns `Option>`. parse_macro_arg!( diff --git a/src/tools/rustfmt/src/patterns.rs b/src/tools/rustfmt/src/patterns.rs index 0a9ff4771b0e0..3694f5d7140ab 100644 --- a/src/tools/rustfmt/src/patterns.rs +++ b/src/tools/rustfmt/src/patterns.rs @@ -539,7 +539,7 @@ impl Rewrite for PatField { #[derive(Debug)] pub(crate) enum TuplePatField<'a> { - Pat(&'a ast::Pat), + Pat(&'a Box), Dotdot(Span), } @@ -596,7 +596,7 @@ pub(crate) fn can_be_overflowed_pat( } fn rewrite_tuple_pat( - pats: &[ast::Pat], + pats: &[Box], path_str: Option, span: Span, context: &RewriteContext<'_>,