Avoid double-boxing lists of THIR subpatterns
This commit is contained in:
parent
d72cc93e4e
commit
869c7b766e
4 changed files with 16 additions and 16 deletions
|
@ -629,7 +629,7 @@ pub enum InlineAsmOperand<'tcx> {
|
|||
#[derive(Clone, Debug, HashStable, TypeVisitable)]
|
||||
pub struct FieldPat<'tcx> {
|
||||
pub field: FieldIdx,
|
||||
pub pattern: Box<Pat<'tcx>>,
|
||||
pub pattern: Pat<'tcx>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, HashStable, TypeVisitable)]
|
||||
|
@ -690,7 +690,7 @@ impl<'tcx> Pat<'tcx> {
|
|||
Or { pats } => pats.iter().for_each(|p| p.walk_(it)),
|
||||
Array { box ref prefix, ref slice, box ref suffix }
|
||||
| Slice { box ref prefix, ref slice, box ref suffix } => {
|
||||
prefix.iter().chain(slice.iter()).chain(suffix.iter()).for_each(|p| p.walk_(it))
|
||||
prefix.iter().chain(slice.as_deref()).chain(suffix.iter()).for_each(|p| p.walk_(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -853,22 +853,22 @@ pub enum PatKind<'tcx> {
|
|||
/// irrefutable when there is a slice pattern and both `prefix` and `suffix` are empty.
|
||||
/// e.g., `&[ref xs @ ..]`.
|
||||
Slice {
|
||||
prefix: Box<[Box<Pat<'tcx>>]>,
|
||||
prefix: Box<[Pat<'tcx>]>,
|
||||
slice: Option<Box<Pat<'tcx>>>,
|
||||
suffix: Box<[Box<Pat<'tcx>>]>,
|
||||
suffix: Box<[Pat<'tcx>]>,
|
||||
},
|
||||
|
||||
/// Fixed match against an array; irrefutable.
|
||||
Array {
|
||||
prefix: Box<[Box<Pat<'tcx>>]>,
|
||||
prefix: Box<[Pat<'tcx>]>,
|
||||
slice: Option<Box<Pat<'tcx>>>,
|
||||
suffix: Box<[Box<Pat<'tcx>>]>,
|
||||
suffix: Box<[Pat<'tcx>]>,
|
||||
},
|
||||
|
||||
/// An or-pattern, e.g. `p | q`.
|
||||
/// Invariant: `pats.len() >= 2`.
|
||||
Or {
|
||||
pats: Box<[Box<Pat<'tcx>>]>,
|
||||
pats: Box<[Pat<'tcx>]>,
|
||||
},
|
||||
|
||||
/// A never pattern `!`.
|
||||
|
|
|
@ -37,9 +37,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
&mut self,
|
||||
match_pairs: &mut Vec<MatchPairTree<'tcx>>,
|
||||
place: &PlaceBuilder<'tcx>,
|
||||
prefix: &[Box<Pat<'tcx>>],
|
||||
prefix: &[Pat<'tcx>],
|
||||
opt_slice: &Option<Box<Pat<'tcx>>>,
|
||||
suffix: &[Box<Pat<'tcx>>],
|
||||
suffix: &[Pat<'tcx>],
|
||||
) {
|
||||
let tcx = self.tcx;
|
||||
let (min_length, exact_size) = if let Some(place_resolved) = place.try_to_place(self) {
|
||||
|
|
|
@ -208,7 +208,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
let field = FieldIdx::new(idx);
|
||||
// Patterns can only use monomorphic types.
|
||||
let ty = self.tcx.normalize_erasing_regions(self.typing_env, ty);
|
||||
FieldPat { field, pattern: self.valtree_to_pat(val, ty) }
|
||||
FieldPat { field, pattern: *self.valtree_to_pat(val, ty) }
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
prefix: cv
|
||||
.unwrap_branch()
|
||||
.iter()
|
||||
.map(|val| self.valtree_to_pat(*val, *elem_ty))
|
||||
.map(|val| *self.valtree_to_pat(*val, *elem_ty))
|
||||
.collect(),
|
||||
slice: None,
|
||||
suffix: Box::new([]),
|
||||
|
@ -286,7 +286,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
prefix: cv
|
||||
.unwrap_branch()
|
||||
.iter()
|
||||
.map(|val| self.valtree_to_pat(*val, *elem_ty))
|
||||
.map(|val| *self.valtree_to_pat(*val, *elem_ty))
|
||||
.collect(),
|
||||
slice: None,
|
||||
suffix: Box::new([]),
|
||||
|
|
|
@ -417,7 +417,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
.iter()
|
||||
.map(|field| FieldPat {
|
||||
field: self.typeck_results.field_index(field.hir_id),
|
||||
pattern: self.lower_pattern(field.pat),
|
||||
pattern: *self.lower_pattern(field.pat),
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
@ -445,13 +445,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
.enumerate_and_adjust(expected_len, gap_pos)
|
||||
.map(|(i, subpattern)| FieldPat {
|
||||
field: FieldIdx::new(i),
|
||||
pattern: self.lower_pattern(subpattern),
|
||||
pattern: *self.lower_pattern(subpattern),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn lower_patterns(&mut self, pats: &'tcx [hir::Pat<'tcx>]) -> Box<[Box<Pat<'tcx>>]> {
|
||||
pats.iter().map(|p| self.lower_pattern(p)).collect()
|
||||
fn lower_patterns(&mut self, pats: &'tcx [hir::Pat<'tcx>]) -> Box<[Pat<'tcx>]> {
|
||||
pats.iter().map(|p| *self.lower_pattern(p)).collect()
|
||||
}
|
||||
|
||||
fn lower_opt_pattern(&mut self, pat: Option<&'tcx hir::Pat<'tcx>>) -> Option<Box<Pat<'tcx>>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue