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)]
|
#[derive(Clone, Debug, HashStable, TypeVisitable)]
|
||||||
pub struct FieldPat<'tcx> {
|
pub struct FieldPat<'tcx> {
|
||||||
pub field: FieldIdx,
|
pub field: FieldIdx,
|
||||||
pub pattern: Box<Pat<'tcx>>,
|
pub pattern: Pat<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, HashStable, TypeVisitable)]
|
#[derive(Clone, Debug, HashStable, TypeVisitable)]
|
||||||
|
@ -690,7 +690,7 @@ impl<'tcx> Pat<'tcx> {
|
||||||
Or { pats } => pats.iter().for_each(|p| p.walk_(it)),
|
Or { pats } => pats.iter().for_each(|p| p.walk_(it)),
|
||||||
Array { box ref prefix, ref slice, box ref suffix }
|
Array { box ref prefix, ref slice, box ref suffix }
|
||||||
| Slice { 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.
|
/// irrefutable when there is a slice pattern and both `prefix` and `suffix` are empty.
|
||||||
/// e.g., `&[ref xs @ ..]`.
|
/// e.g., `&[ref xs @ ..]`.
|
||||||
Slice {
|
Slice {
|
||||||
prefix: Box<[Box<Pat<'tcx>>]>,
|
prefix: Box<[Pat<'tcx>]>,
|
||||||
slice: Option<Box<Pat<'tcx>>>,
|
slice: Option<Box<Pat<'tcx>>>,
|
||||||
suffix: Box<[Box<Pat<'tcx>>]>,
|
suffix: Box<[Pat<'tcx>]>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Fixed match against an array; irrefutable.
|
/// Fixed match against an array; irrefutable.
|
||||||
Array {
|
Array {
|
||||||
prefix: Box<[Box<Pat<'tcx>>]>,
|
prefix: Box<[Pat<'tcx>]>,
|
||||||
slice: Option<Box<Pat<'tcx>>>,
|
slice: Option<Box<Pat<'tcx>>>,
|
||||||
suffix: Box<[Box<Pat<'tcx>>]>,
|
suffix: Box<[Pat<'tcx>]>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// An or-pattern, e.g. `p | q`.
|
/// An or-pattern, e.g. `p | q`.
|
||||||
/// Invariant: `pats.len() >= 2`.
|
/// Invariant: `pats.len() >= 2`.
|
||||||
Or {
|
Or {
|
||||||
pats: Box<[Box<Pat<'tcx>>]>,
|
pats: Box<[Pat<'tcx>]>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// A never pattern `!`.
|
/// A never pattern `!`.
|
||||||
|
|
|
@ -37,9 +37,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
match_pairs: &mut Vec<MatchPairTree<'tcx>>,
|
match_pairs: &mut Vec<MatchPairTree<'tcx>>,
|
||||||
place: &PlaceBuilder<'tcx>,
|
place: &PlaceBuilder<'tcx>,
|
||||||
prefix: &[Box<Pat<'tcx>>],
|
prefix: &[Pat<'tcx>],
|
||||||
opt_slice: &Option<Box<Pat<'tcx>>>,
|
opt_slice: &Option<Box<Pat<'tcx>>>,
|
||||||
suffix: &[Box<Pat<'tcx>>],
|
suffix: &[Pat<'tcx>],
|
||||||
) {
|
) {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let (min_length, exact_size) = if let Some(place_resolved) = place.try_to_place(self) {
|
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);
|
let field = FieldIdx::new(idx);
|
||||||
// Patterns can only use monomorphic types.
|
// Patterns can only use monomorphic types.
|
||||||
let ty = self.tcx.normalize_erasing_regions(self.typing_env, ty);
|
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()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -277,7 +277,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
||||||
prefix: cv
|
prefix: cv
|
||||||
.unwrap_branch()
|
.unwrap_branch()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|val| self.valtree_to_pat(*val, *elem_ty))
|
.map(|val| *self.valtree_to_pat(*val, *elem_ty))
|
||||||
.collect(),
|
.collect(),
|
||||||
slice: None,
|
slice: None,
|
||||||
suffix: Box::new([]),
|
suffix: Box::new([]),
|
||||||
|
@ -286,7 +286,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
||||||
prefix: cv
|
prefix: cv
|
||||||
.unwrap_branch()
|
.unwrap_branch()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|val| self.valtree_to_pat(*val, *elem_ty))
|
.map(|val| *self.valtree_to_pat(*val, *elem_ty))
|
||||||
.collect(),
|
.collect(),
|
||||||
slice: None,
|
slice: None,
|
||||||
suffix: Box::new([]),
|
suffix: Box::new([]),
|
||||||
|
|
|
@ -417,7 +417,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|field| FieldPat {
|
.map(|field| FieldPat {
|
||||||
field: self.typeck_results.field_index(field.hir_id),
|
field: self.typeck_results.field_index(field.hir_id),
|
||||||
pattern: self.lower_pattern(field.pat),
|
pattern: *self.lower_pattern(field.pat),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
@ -445,13 +445,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
||||||
.enumerate_and_adjust(expected_len, gap_pos)
|
.enumerate_and_adjust(expected_len, gap_pos)
|
||||||
.map(|(i, subpattern)| FieldPat {
|
.map(|(i, subpattern)| FieldPat {
|
||||||
field: FieldIdx::new(i),
|
field: FieldIdx::new(i),
|
||||||
pattern: self.lower_pattern(subpattern),
|
pattern: *self.lower_pattern(subpattern),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_patterns(&mut self, pats: &'tcx [hir::Pat<'tcx>]) -> Box<[Box<Pat<'tcx>>]> {
|
fn lower_patterns(&mut self, pats: &'tcx [hir::Pat<'tcx>]) -> Box<[Pat<'tcx>]> {
|
||||||
pats.iter().map(|p| self.lower_pattern(p)).collect()
|
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>>> {
|
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