Factor out pushing onto PatternColumn
This commit is contained in:
parent
d8b44d2802
commit
4c2386137a
1 changed files with 12 additions and 12 deletions
|
@ -33,16 +33,20 @@ pub(crate) struct PatternColumn<'p, 'tcx> {
|
||||||
|
|
||||||
impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
|
impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
|
||||||
pub(crate) fn new(arms: &[MatchArm<'p, 'tcx>]) -> Self {
|
pub(crate) fn new(arms: &[MatchArm<'p, 'tcx>]) -> Self {
|
||||||
let mut patterns = Vec::with_capacity(arms.len());
|
let patterns = Vec::with_capacity(arms.len());
|
||||||
|
let mut column = PatternColumn { patterns };
|
||||||
for arm in arms {
|
for arm in arms {
|
||||||
if arm.pat.is_or_pat() {
|
column.expand_and_push(arm.pat);
|
||||||
patterns.extend(arm.pat.flatten_or_pat())
|
}
|
||||||
|
column
|
||||||
|
}
|
||||||
|
fn expand_and_push(&mut self, pat: &'p DeconstructedPat<'p, 'tcx>) {
|
||||||
|
if pat.is_or_pat() {
|
||||||
|
self.patterns.extend(pat.flatten_or_pat())
|
||||||
} else {
|
} else {
|
||||||
patterns.push(arm.pat)
|
self.patterns.push(pat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self { patterns }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
self.patterns.is_empty()
|
self.patterns.is_empty()
|
||||||
|
@ -87,11 +91,7 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
|
||||||
for pat in relevant_patterns {
|
for pat in relevant_patterns {
|
||||||
let specialized = pat.specialize(pcx, ctor, ctor_sub_tys);
|
let specialized = pat.specialize(pcx, ctor, ctor_sub_tys);
|
||||||
for (subpat, column) in specialized.iter().zip(&mut specialized_columns) {
|
for (subpat, column) in specialized.iter().zip(&mut specialized_columns) {
|
||||||
if subpat.is_or_pat() {
|
column.expand_and_push(subpat);
|
||||||
column.patterns.extend(subpat.flatten_or_pat())
|
|
||||||
} else {
|
|
||||||
column.patterns.push(subpat)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue