Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,11 +887,11 @@ pub enum PatKind {
Struct(Option<Box<QSelf>>, Path, ThinVec<PatField>, PatFieldsRest),

/// A tuple struct/variant pattern (`Variant(x, y, .., z)`).
TupleStruct(Option<Box<QSelf>>, Path, ThinVec<Pat>),
TupleStruct(Option<Box<QSelf>>, Path, ThinVec<Box<Pat>>),

/// An or-pattern `A | B | C`.
/// Invariant: `pats.len() >= 2`.
Or(ThinVec<Pat>),
Or(ThinVec<Box<Pat>>),

/// A possibly qualified path pattern.
/// Unqualified path patterns `A::B::C` can legally refer to variants, structs, constants
Expand All @@ -900,7 +900,7 @@ pub enum PatKind {
Path(Option<Box<QSelf>>, Path),

/// A tuple pattern (`(a, b)`).
Tuple(ThinVec<Pat>),
Tuple(ThinVec<Box<Pat>>),

/// A `box` pattern.
Box(Box<Pat>),
Expand All @@ -918,7 +918,7 @@ pub enum PatKind {
Range(Option<Box<Expr>>, Option<Box<Expr>>, Spanned<RangeEnd>),

/// A slice pattern `[a, b, c]`.
Slice(ThinVec<Pat>),
Slice(ThinVec<Box<Pat>>),

/// A rest pattern `..`.
///
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ macro_rules! common_visitor_and_walkers {
ThinVec<(NodeId, Path)>,
ThinVec<PathSegment>,
ThinVec<PreciseCapturingArg>,
ThinVec<Pat>,
ThinVec<Box<Pat>>,
ThinVec<Box<Ty>>,
ThinVec<TyPat>,
ThinVec<EiiImpl>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

fn lower_pat_tuple(
&mut self,
pats: &[Pat],
pats: &[Box<Pat>],
ctx: &str,
) -> (&'hir [hir::Pat<'hir>], hir::DotDotPos) {
let mut elems = Vec::with_capacity(pats.len());
Expand Down Expand Up @@ -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<Pat>]) -> hir::PatKind<'hir> {
let mut before = Vec::new();
let mut after = Vec::new();
let mut slice = None;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ impl<'a> TraitDef<'a> {
struct_def: &'a VariantData,
prefixes: &[String],
by_ref: ByRef,
) -> ThinVec<ast::Pat> {
) -> ThinVec<Box<ast::Pat>> {
prefixes
.iter()
.map(|prefix| {
Expand Down Expand Up @@ -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,
}
})
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/offload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/pattern_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ast::Pat>) -> TyPat {
let kind = match pat.kind {
ast::PatKind::Range(start, end, include_end) => TyPatKind::Range(
start.map(|value| {
Expand All @@ -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)
Expand Down
35 changes: 17 additions & 18 deletions compiler/rustc_expand/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -253,7 +253,7 @@ impl<'a> ExtCtxt<'a> {
pub fn stmt_let_type_only(&self, span: Span, ty: Box<ast::Ty>) -> 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,
Expand Down Expand Up @@ -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<ast::Pat> {
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<ast::Pat> {
self.pat(span, PatKind::Wild)
}
pub fn pat_lit(&self, span: Span, expr: Box<ast::Expr>) -> ast::Pat {
pub fn pat_lit(&self, span: Span, expr: Box<ast::Expr>) -> Box<ast::Pat> {
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<ast::Pat> {
self.pat_ident_binding_mode(span, ident, ast::BindingMode::NONE)
}

Expand All @@ -550,43 +550,43 @@ impl<'a> ExtCtxt<'a> {
span: Span,
ident: Ident,
ann: ast::BindingMode,
) -> ast::Pat {
) -> Box<ast::Pat> {
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<ast::Pat> {
self.pat(span, PatKind::Path(None, path))
}
pub fn pat_tuple_struct(
&self,
span: Span,
path: ast::Path,
subpats: ThinVec<ast::Pat>,
) -> ast::Pat {
subpats: ThinVec<Box<ast::Pat>>,
) -> Box<ast::Pat> {
self.pat(span, PatKind::TupleStruct(None, path, subpats))
}
pub fn pat_struct(
&self,
span: Span,
path: ast::Path,
field_pats: ThinVec<ast::PatField>,
) -> ast::Pat {
) -> Box<ast::Pat> {
self.pat(span, PatKind::Struct(None, path, field_pats, ast::PatFieldsRest::None))
}
pub fn pat_tuple(&self, span: Span, pats: ThinVec<ast::Pat>) -> ast::Pat {
pub fn pat_tuple(&self, span: Span, pats: ThinVec<Box<ast::Pat>>) -> Box<ast::Pat> {
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<ast::Pat>) -> Box<ast::Pat> {
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::Expr>) -> ast::Arm {
pub fn arm(&self, span: Span, pat: Box<ast::Pat>, expr: Box<ast::Expr>) -> ast::Arm {
ast::Arm {
attrs: AttrVec::new(),
pat: Box::new(pat),
pat,
guard: None,
body: Some(expr),
span,
Expand Down Expand Up @@ -665,11 +665,10 @@ impl<'a> ExtCtxt<'a> {
}

pub fn param(&self, span: Span, ident: Ident, ty: Box<ast::Ty>) -> 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,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pat>,
expected: Option<Expected>,
) -> Pat {
) -> Box<Pat> {
if token::Colon != self.token.kind {
return first_pat;
}
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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<Expr>)> {
pub fn parse_for_head(&mut self) -> PResult<'a, (Box<Pat>, Box<Expr>)> {
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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Box<Guard>>)> {
fn parse_match_arm_pat_and_guard(&mut self) -> PResult<'a, (Box<Pat>, Option<Box<Guard>>)> {
if self.token == token::OpenParen {
let left = self.token.span;
let pat = self.parse_pat_no_top_guard(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_parse/src/parser/nonterminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ impl<'a> Parser<'a> {
RecoverColon::No,
CommaRecoveryMode::EitherTupleOrPipe,
),
})
.map(Box::new)?,
})?,
pat_kind,
)),
NonterminalKind::Expr(expr_kind) => {
Expand Down
Loading
Loading