diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2020-11-18 22:07:37 +0000 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2020-11-27 18:20:30 +0000 |
| commit | d447bdff9b44ab4f298e1d986a02e51997540b08 (patch) | |
| tree | a5d7dc704bf7140ad8166ccef51d9059ff82f926 /compiler | |
| parent | b59792128ce235e9dfae921aa5cecf89106b0b53 (diff) | |
| download | rust-d447bdff9b44ab4f298e1d986a02e51997540b08.tar.gz rust-d447bdff9b44ab4f298e1d986a02e51997540b08.zip | |
Disentangle `Fields` and `PatStack`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/pattern/_match.rs | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/compiler/rustc_mir_build/src/thir/pattern/_match.rs b/compiler/rustc_mir_build/src/thir/pattern/_match.rs index 75c12f379af..29364107954 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/_match.rs @@ -437,8 +437,10 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> { fn pop_head_constructor(&self, ctor_wild_subpatterns: &Fields<'p, 'tcx>) -> PatStack<'p, 'tcx> { // We pop the head pattern and push the new fields extracted from the arguments of // `self.head()`. - let new_fields = ctor_wild_subpatterns.replace_with_pattern_arguments(self.head()); - new_fields.push_on_patstack(&self.pats[1..]) + let mut new_fields = + ctor_wild_subpatterns.replace_with_pattern_arguments(self.head()).filtered_patterns(); + new_fields.extend_from_slice(&self.pats[1..]); + PatStack::from_vec(new_fields) } } @@ -1252,6 +1254,18 @@ impl<'p, 'tcx> Fields<'p, 'tcx> { pats.into_iter() } + /// Returns the filtered list of patterns, not including hidden fields. + fn filtered_patterns(self) -> SmallVec<[&'p Pat<'tcx>; 2]> { + match self { + Fields::Slice(pats) => pats.iter().collect(), + Fields::Vec(pats) => pats, + Fields::Filtered { fields, .. } => { + // We skip hidden fields here + fields.into_iter().filter_map(|p| p.kept()).collect() + } + } + } + /// Overrides some of the fields with the provided patterns. Exactly like /// `replace_fields_indexed`, except that it takes `FieldPat`s as input. fn replace_with_fieldpats( @@ -1358,21 +1372,6 @@ impl<'p, 'tcx> Fields<'p, 'tcx> { _ => self.clone(), } } - - fn push_on_patstack(self, stack: &[&'p Pat<'tcx>]) -> PatStack<'p, 'tcx> { - let pats: SmallVec<_> = match self { - Fields::Slice(pats) => pats.iter().chain(stack.iter().copied()).collect(), - Fields::Vec(mut pats) => { - pats.extend_from_slice(stack); - pats - } - Fields::Filtered { fields, .. } => { - // We skip hidden fields here - fields.into_iter().filter_map(|p| p.kept()).chain(stack.iter().copied()).collect() - } - }; - PatStack::from_vec(pats) - } } #[derive(Clone, Debug)] |
