Skip to content

Commit 0421444

Browse files
committed
Auto merge of rust-lang#101139 - nnethercote:shrink-thir-Pat, r=cjgillot
Shrink `thir::Pat` r? `@cjgillot`
2 parents 0209485 + 43a0268 commit 0421444

File tree

19 files changed

+205
-181
lines changed

19 files changed

+205
-181
lines changed

compiler/rustc_middle/src/thir.rs

+31-31
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub enum StmtKind<'tcx> {
180180
/// `let <PAT> = ...`
181181
///
182182
/// If a type annotation is included, it is added as an ascription pattern.
183-
pattern: Pat<'tcx>,
183+
pattern: Box<Pat<'tcx>>,
184184

185185
/// `let pat: ty = <INIT>`
186186
initializer: Option<ExprId>,
@@ -301,7 +301,7 @@ pub enum ExprKind<'tcx> {
301301
},
302302
Let {
303303
expr: ExprId,
304-
pat: Pat<'tcx>,
304+
pat: Box<Pat<'tcx>>,
305305
},
306306
/// A `match` expression.
307307
Match {
@@ -467,7 +467,7 @@ pub struct FruInfo<'tcx> {
467467
/// A `match` arm.
468468
#[derive(Clone, Debug, HashStable)]
469469
pub struct Arm<'tcx> {
470-
pub pattern: Pat<'tcx>,
470+
pub pattern: Box<Pat<'tcx>>,
471471
pub guard: Option<Guard<'tcx>>,
472472
pub body: ExprId,
473473
pub lint_level: LintLevel,
@@ -479,7 +479,7 @@ pub struct Arm<'tcx> {
479479
#[derive(Clone, Debug, HashStable)]
480480
pub enum Guard<'tcx> {
481481
If(ExprId),
482-
IfLet(Pat<'tcx>, ExprId),
482+
IfLet(Box<Pat<'tcx>>, ExprId),
483483
}
484484

485485
#[derive(Copy, Clone, Debug, HashStable)]
@@ -534,19 +534,19 @@ pub enum BindingMode {
534534
#[derive(Clone, Debug, HashStable)]
535535
pub struct FieldPat<'tcx> {
536536
pub field: Field,
537-
pub pattern: Pat<'tcx>,
537+
pub pattern: Box<Pat<'tcx>>,
538538
}
539539

540540
#[derive(Clone, Debug, HashStable)]
541541
pub struct Pat<'tcx> {
542542
pub ty: Ty<'tcx>,
543543
pub span: Span,
544-
pub kind: Box<PatKind<'tcx>>,
544+
pub kind: PatKind<'tcx>,
545545
}
546546

547547
impl<'tcx> Pat<'tcx> {
548548
pub fn wildcard_from_ty(ty: Ty<'tcx>) -> Self {
549-
Pat { ty, span: DUMMY_SP, kind: Box::new(PatKind::Wild) }
549+
Pat { ty, span: DUMMY_SP, kind: PatKind::Wild }
550550
}
551551
}
552552

@@ -581,7 +581,7 @@ pub enum PatKind<'tcx> {
581581

582582
AscribeUserType {
583583
ascription: Ascription<'tcx>,
584-
subpattern: Pat<'tcx>,
584+
subpattern: Box<Pat<'tcx>>,
585585
},
586586

587587
/// `x`, `ref x`, `x @ P`, etc.
@@ -591,7 +591,7 @@ pub enum PatKind<'tcx> {
591591
mode: BindingMode,
592592
var: LocalVarId,
593593
ty: Ty<'tcx>,
594-
subpattern: Option<Pat<'tcx>>,
594+
subpattern: Option<Box<Pat<'tcx>>>,
595595
/// Is this the leftmost occurrence of the binding, i.e., is `var` the
596596
/// `HirId` of this pattern?
597597
is_primary: bool,
@@ -614,7 +614,7 @@ pub enum PatKind<'tcx> {
614614

615615
/// `box P`, `&P`, `&mut P`, etc.
616616
Deref {
617-
subpattern: Pat<'tcx>,
617+
subpattern: Box<Pat<'tcx>>,
618618
},
619619

620620
/// One of the following:
@@ -628,32 +628,32 @@ pub enum PatKind<'tcx> {
628628
value: mir::ConstantKind<'tcx>,
629629
},
630630

631-
Range(PatRange<'tcx>),
631+
Range(Box<PatRange<'tcx>>),
632632

633633
/// Matches against a slice, checking the length and extracting elements.
634634
/// irrefutable when there is a slice pattern and both `prefix` and `suffix` are empty.
635635
/// e.g., `&[ref xs @ ..]`.
636636
Slice {
637-
prefix: Vec<Pat<'tcx>>,
638-
slice: Option<Pat<'tcx>>,
639-
suffix: Vec<Pat<'tcx>>,
637+
prefix: Box<[Box<Pat<'tcx>>]>,
638+
slice: Option<Box<Pat<'tcx>>>,
639+
suffix: Box<[Box<Pat<'tcx>>]>,
640640
},
641641

642642
/// Fixed match against an array; irrefutable.
643643
Array {
644-
prefix: Vec<Pat<'tcx>>,
645-
slice: Option<Pat<'tcx>>,
646-
suffix: Vec<Pat<'tcx>>,
644+
prefix: Box<[Box<Pat<'tcx>>]>,
645+
slice: Option<Box<Pat<'tcx>>>,
646+
suffix: Box<[Box<Pat<'tcx>>]>,
647647
},
648648

649649
/// An or-pattern, e.g. `p | q`.
650650
/// Invariant: `pats.len() >= 2`.
651651
Or {
652-
pats: Vec<Pat<'tcx>>,
652+
pats: Box<[Box<Pat<'tcx>>]>,
653653
},
654654
}
655655

656-
#[derive(Copy, Clone, Debug, PartialEq, HashStable)]
656+
#[derive(Clone, Debug, PartialEq, HashStable)]
657657
pub struct PatRange<'tcx> {
658658
pub lo: mir::ConstantKind<'tcx>,
659659
pub hi: mir::ConstantKind<'tcx>,
@@ -674,7 +674,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
674674
};
675675
let mut start_or_comma = || start_or_continue(", ");
676676

677-
match *self.kind {
677+
match self.kind {
678678
PatKind::Wild => write!(f, "_"),
679679
PatKind::AscribeUserType { ref subpattern, .. } => write!(f, "{}: _", subpattern),
680680
PatKind::Binding { mutability, name, mode, ref subpattern, .. } => {
@@ -695,7 +695,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
695695
Ok(())
696696
}
697697
PatKind::Variant { ref subpatterns, .. } | PatKind::Leaf { ref subpatterns } => {
698-
let variant = match *self.kind {
698+
let variant = match self.kind {
699699
PatKind::Variant { adt_def, variant_index, .. } => {
700700
Some(adt_def.variant(variant_index))
701701
}
@@ -714,7 +714,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
714714

715715
let mut printed = 0;
716716
for p in subpatterns {
717-
if let PatKind::Wild = *p.pattern.kind {
717+
if let PatKind::Wild = p.pattern.kind {
718718
continue;
719719
}
720720
let name = variant.fields[p.field.index()].name;
@@ -767,32 +767,32 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
767767
write!(f, "{}", subpattern)
768768
}
769769
PatKind::Constant { value } => write!(f, "{}", value),
770-
PatKind::Range(PatRange { lo, hi, end }) => {
770+
PatKind::Range(box PatRange { lo, hi, end }) => {
771771
write!(f, "{}", lo)?;
772772
write!(f, "{}", end)?;
773773
write!(f, "{}", hi)
774774
}
775775
PatKind::Slice { ref prefix, ref slice, ref suffix }
776776
| PatKind::Array { ref prefix, ref slice, ref suffix } => {
777777
write!(f, "[")?;
778-
for p in prefix {
778+
for p in prefix.iter() {
779779
write!(f, "{}{}", start_or_comma(), p)?;
780780
}
781781
if let Some(ref slice) = *slice {
782782
write!(f, "{}", start_or_comma())?;
783-
match *slice.kind {
783+
match slice.kind {
784784
PatKind::Wild => {}
785785
_ => write!(f, "{}", slice)?,
786786
}
787787
write!(f, "..")?;
788788
}
789-
for p in suffix {
789+
for p in suffix.iter() {
790790
write!(f, "{}{}", start_or_comma(), p)?;
791791
}
792792
write!(f, "]")
793793
}
794794
PatKind::Or { ref pats } => {
795-
for pat in pats {
795+
for pat in pats.iter() {
796796
write!(f, "{}{}", start_or_continue(" | "), pat)?;
797797
}
798798
Ok(())
@@ -809,8 +809,8 @@ mod size_asserts {
809809
static_assert_size!(Block, 56);
810810
static_assert_size!(Expr<'_>, 64);
811811
static_assert_size!(ExprKind<'_>, 40);
812-
static_assert_size!(Pat<'_>, 24);
813-
static_assert_size!(PatKind<'_>, 112);
814-
static_assert_size!(Stmt<'_>, 72);
815-
static_assert_size!(StmtKind<'_>, 64);
812+
static_assert_size!(Pat<'_>, 72);
813+
static_assert_size!(PatKind<'_>, 56);
814+
static_assert_size!(Stmt<'_>, 56);
815+
static_assert_size!(StmtKind<'_>, 48);
816816
}

compiler/rustc_middle/src/thir/visit.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub fn walk_arm<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, arm: &Arm<'
211211

212212
pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'tcx>) {
213213
use PatKind::*;
214-
match pat.kind.as_ref() {
214+
match &pat.kind {
215215
AscribeUserType { subpattern, ascription: _ }
216216
| Deref { subpattern }
217217
| Binding {
@@ -232,18 +232,18 @@ pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'
232232
Constant { value: _ } => {}
233233
Range(_) => {}
234234
Slice { prefix, slice, suffix } | Array { prefix, slice, suffix } => {
235-
for subpattern in prefix {
235+
for subpattern in prefix.iter() {
236236
visitor.visit_pat(&subpattern);
237237
}
238238
if let Some(pat) = slice {
239-
visitor.visit_pat(pat);
239+
visitor.visit_pat(&pat);
240240
}
241-
for subpattern in suffix {
241+
for subpattern in suffix.iter() {
242242
visitor.visit_pat(&subpattern);
243243
}
244244
}
245245
Or { pats } => {
246-
for pat in pats {
246+
for pat in pats.iter() {
247247
visitor.visit_pat(&pat);
248248
}
249249
}

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ pub type CanonicalUserTypeAnnotations<'tcx> =
874874

875875
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable, Lift)]
876876
pub struct CanonicalUserTypeAnnotation<'tcx> {
877-
pub user_ty: CanonicalUserType<'tcx>,
877+
pub user_ty: Box<CanonicalUserType<'tcx>>,
878878
pub span: Span,
879879
pub inferred_ty: Ty<'tcx>,
880880
}

compiler/rustc_mir_build/src/build/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
117117
lint_level,
118118
else_block,
119119
} => {
120-
let ignores_expr_result = matches!(*pattern.kind, PatKind::Wild);
120+
let ignores_expr_result = matches!(pattern.kind, PatKind::Wild);
121121
this.block_context.push(BlockFrame::Statement { ignores_expr_result });
122122

123123
// Enter the remainder scope, i.e., the bindings' destruction scope.
@@ -160,7 +160,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
160160
ArmHasGuard(false),
161161
Some((None, initializer_span)),
162162
);
163-
this.expr_into_pattern(block, pattern.clone(), init) // irrefutable pattern
163+
this.expr_into_pattern(block, pattern, init) // irrefutable pattern
164164
}
165165
})
166166
},

compiler/rustc_mir_build/src/build/expr/as_constant.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4242
Constant { span, user_ty: None, literal }
4343
}
4444
ExprKind::NonHirLiteral { lit, ref user_ty } => {
45-
let user_ty = user_ty.as_ref().map(|box user_ty| {
45+
let user_ty = user_ty.as_ref().map(|user_ty| {
4646
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
4747
span,
48-
user_ty: *user_ty,
48+
user_ty: user_ty.clone(),
4949
inferred_ty: ty,
5050
})
5151
});
@@ -54,10 +54,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5454
Constant { span, user_ty: user_ty, literal }
5555
}
5656
ExprKind::ZstLiteral { ref user_ty } => {
57-
let user_ty = user_ty.as_ref().map(|box user_ty| {
57+
let user_ty = user_ty.as_ref().map(|user_ty| {
5858
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
5959
span,
60-
user_ty: *user_ty,
60+
user_ty: user_ty.clone(),
6161
inferred_ty: ty,
6262
})
6363
});
@@ -66,10 +66,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6666
Constant { span, user_ty: user_ty, literal }
6767
}
6868
ExprKind::NamedConst { def_id, substs, ref user_ty } => {
69-
let user_ty = user_ty.as_ref().map(|box user_ty| {
69+
let user_ty = user_ty.as_ref().map(|user_ty| {
7070
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
7171
span,
72-
user_ty: *user_ty,
72+
user_ty: user_ty.clone(),
7373
inferred_ty: ty,
7474
})
7575
});

compiler/rustc_mir_build/src/build/expr/as_place.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
522522
fake_borrow_temps,
523523
)
524524
);
525-
if let Some(box user_ty) = user_ty {
525+
if let Some(user_ty) = user_ty {
526526
let annotation_index =
527527
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
528528
span: source_info.span,
529-
user_ty: *user_ty,
529+
user_ty: user_ty.clone(),
530530
inferred_ty: expr.ty,
531531
});
532532

@@ -551,11 +551,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
551551
let source = &this.thir[source];
552552
let temp =
553553
unpack!(block = this.as_temp(block, source.temp_lifetime, source, mutability));
554-
if let Some(box user_ty) = user_ty {
554+
if let Some(user_ty) = user_ty {
555555
let annotation_index =
556556
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
557557
span: source_info.span,
558-
user_ty: *user_ty,
558+
user_ty: user_ty.clone(),
559559
inferred_ty: expr.ty,
560560
});
561561
this.cfg.push(

compiler/rustc_mir_build/src/build/expr/into.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
378378
};
379379

380380
let inferred_ty = expr.ty;
381-
let user_ty = user_ty.as_ref().map(|box user_ty| {
381+
let user_ty = user_ty.as_ref().map(|user_ty| {
382382
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
383383
span: source_info.span,
384-
user_ty: *user_ty,
384+
user_ty: user_ty.clone(),
385385
inferred_ty,
386386
})
387387
});

0 commit comments

Comments
 (0)