Skip to content

Commit 869c7b7

Browse files
committed
Avoid double-boxing lists of THIR subpatterns
1 parent d72cc93 commit 869c7b7

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

Diff for: compiler/rustc_middle/src/thir.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ pub enum InlineAsmOperand<'tcx> {
629629
#[derive(Clone, Debug, HashStable, TypeVisitable)]
630630
pub struct FieldPat<'tcx> {
631631
pub field: FieldIdx,
632-
pub pattern: Box<Pat<'tcx>>,
632+
pub pattern: Pat<'tcx>,
633633
}
634634

635635
#[derive(Clone, Debug, HashStable, TypeVisitable)]
@@ -690,7 +690,7 @@ impl<'tcx> Pat<'tcx> {
690690
Or { pats } => pats.iter().for_each(|p| p.walk_(it)),
691691
Array { box ref prefix, ref slice, box ref suffix }
692692
| Slice { box ref prefix, ref slice, box ref suffix } => {
693-
prefix.iter().chain(slice.iter()).chain(suffix.iter()).for_each(|p| p.walk_(it))
693+
prefix.iter().chain(slice.as_deref()).chain(suffix.iter()).for_each(|p| p.walk_(it))
694694
}
695695
}
696696
}
@@ -853,22 +853,22 @@ pub enum PatKind<'tcx> {
853853
/// irrefutable when there is a slice pattern and both `prefix` and `suffix` are empty.
854854
/// e.g., `&[ref xs @ ..]`.
855855
Slice {
856-
prefix: Box<[Box<Pat<'tcx>>]>,
856+
prefix: Box<[Pat<'tcx>]>,
857857
slice: Option<Box<Pat<'tcx>>>,
858-
suffix: Box<[Box<Pat<'tcx>>]>,
858+
suffix: Box<[Pat<'tcx>]>,
859859
},
860860

861861
/// Fixed match against an array; irrefutable.
862862
Array {
863-
prefix: Box<[Box<Pat<'tcx>>]>,
863+
prefix: Box<[Pat<'tcx>]>,
864864
slice: Option<Box<Pat<'tcx>>>,
865-
suffix: Box<[Box<Pat<'tcx>>]>,
865+
suffix: Box<[Pat<'tcx>]>,
866866
},
867867

868868
/// An or-pattern, e.g. `p | q`.
869869
/// Invariant: `pats.len() >= 2`.
870870
Or {
871-
pats: Box<[Box<Pat<'tcx>>]>,
871+
pats: Box<[Pat<'tcx>]>,
872872
},
873873

874874
/// A never pattern `!`.

Diff for: compiler/rustc_mir_build/src/builder/matches/match_pair.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3737
&mut self,
3838
match_pairs: &mut Vec<MatchPairTree<'tcx>>,
3939
place: &PlaceBuilder<'tcx>,
40-
prefix: &[Box<Pat<'tcx>>],
40+
prefix: &[Pat<'tcx>],
4141
opt_slice: &Option<Box<Pat<'tcx>>>,
42-
suffix: &[Box<Pat<'tcx>>],
42+
suffix: &[Pat<'tcx>],
4343
) {
4444
let tcx = self.tcx;
4545
let (min_length, exact_size) = if let Some(place_resolved) = place.try_to_place(self) {

Diff for: compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl<'tcx> ConstToPat<'tcx> {
208208
let field = FieldIdx::new(idx);
209209
// Patterns can only use monomorphic types.
210210
let ty = self.tcx.normalize_erasing_regions(self.typing_env, ty);
211-
FieldPat { field, pattern: self.valtree_to_pat(val, ty) }
211+
FieldPat { field, pattern: *self.valtree_to_pat(val, ty) }
212212
})
213213
.collect()
214214
}
@@ -277,7 +277,7 @@ impl<'tcx> ConstToPat<'tcx> {
277277
prefix: cv
278278
.unwrap_branch()
279279
.iter()
280-
.map(|val| self.valtree_to_pat(*val, *elem_ty))
280+
.map(|val| *self.valtree_to_pat(*val, *elem_ty))
281281
.collect(),
282282
slice: None,
283283
suffix: Box::new([]),
@@ -286,7 +286,7 @@ impl<'tcx> ConstToPat<'tcx> {
286286
prefix: cv
287287
.unwrap_branch()
288288
.iter()
289-
.map(|val| self.valtree_to_pat(*val, *elem_ty))
289+
.map(|val| *self.valtree_to_pat(*val, *elem_ty))
290290
.collect(),
291291
slice: None,
292292
suffix: Box::new([]),

Diff for: compiler/rustc_mir_build/src/thir/pattern/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
417417
.iter()
418418
.map(|field| FieldPat {
419419
field: self.typeck_results.field_index(field.hir_id),
420-
pattern: self.lower_pattern(field.pat),
420+
pattern: *self.lower_pattern(field.pat),
421421
})
422422
.collect();
423423

@@ -445,13 +445,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
445445
.enumerate_and_adjust(expected_len, gap_pos)
446446
.map(|(i, subpattern)| FieldPat {
447447
field: FieldIdx::new(i),
448-
pattern: self.lower_pattern(subpattern),
448+
pattern: *self.lower_pattern(subpattern),
449449
})
450450
.collect()
451451
}
452452

453-
fn lower_patterns(&mut self, pats: &'tcx [hir::Pat<'tcx>]) -> Box<[Box<Pat<'tcx>>]> {
454-
pats.iter().map(|p| self.lower_pattern(p)).collect()
453+
fn lower_patterns(&mut self, pats: &'tcx [hir::Pat<'tcx>]) -> Box<[Pat<'tcx>]> {
454+
pats.iter().map(|p| *self.lower_pattern(p)).collect()
455455
}
456456

457457
fn lower_opt_pattern(&mut self, pat: Option<&'tcx hir::Pat<'tcx>>) -> Option<Box<Pat<'tcx>>> {

0 commit comments

Comments
 (0)