diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2024-01-03 01:25:32 +0100 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2024-01-07 19:20:19 +0100 |
| commit | 1a3edc169b849108a635724a30166786d43002c0 (patch) | |
| tree | 6c0ef3156d42a95d90037e01c0e0920923929993 /compiler/rustc_pattern_analysis/src | |
| parent | 4ae2840e84515edacee07ee7512ee50e51746c9d (diff) | |
| download | rust-1a3edc169b849108a635724a30166786d43002c0.tar.gz rust-1a3edc169b849108a635724a30166786d43002c0.zip | |
We only need the arity of the subtype list now
Diffstat (limited to 'compiler/rustc_pattern_analysis/src')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/lints.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/pat.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/usefulness.rs | 16 |
3 files changed, 13 insertions, 18 deletions
diff --git a/compiler/rustc_pattern_analysis/src/lints.rs b/compiler/rustc_pattern_analysis/src/lints.rs index 4fdbbfa8578..9b74c251d29 100644 --- a/compiler/rustc_pattern_analysis/src/lints.rs +++ b/compiler/rustc_pattern_analysis/src/lints.rs @@ -88,9 +88,8 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> { (0..arity).map(|_| Self { patterns: Vec::new() }).collect(); let relevant_patterns = self.patterns.iter().filter(|pat| ctor.is_covered_by(pcx, pat.ctor())); - let ctor_sub_tys = pcx.ctor_sub_tys(ctor); for pat in relevant_patterns { - let specialized = pat.specialize(pcx, ctor, ctor_sub_tys); + let specialized = pat.specialize(ctor, arity); for (subpat, column) in specialized.into_iter().zip(&mut specialized_columns) { column.expand_and_push(subpat); } diff --git a/compiler/rustc_pattern_analysis/src/pat.rs b/compiler/rustc_pattern_analysis/src/pat.rs index 9194d6dcdff..3945a5d8a33 100644 --- a/compiler/rustc_pattern_analysis/src/pat.rs +++ b/compiler/rustc_pattern_analysis/src/pat.rs @@ -72,11 +72,10 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> { /// `other_ctor` can be different from `self.ctor`, but must be covered by it. pub(crate) fn specialize( &self, - _pcx: &PlaceCtxt<'_, 'p, Cx>, other_ctor: &Constructor<Cx>, - ctor_sub_tys: &[Cx::Ty], + ctor_arity: usize, ) -> SmallVec<[PatOrWild<'p, Cx>; 2]> { - let wildcard_sub_tys = || ctor_sub_tys.iter().map(|_| Wild).collect(); + let wildcard_sub_tys = || (0..ctor_arity).map(|_| Wild).collect(); match (&self.ctor, other_ctor) { // Return a wildcard for each field of `other_ctor`. (Wildcard, _) => wildcard_sub_tys(), @@ -195,13 +194,12 @@ impl<'p, Cx: TypeCx> PatOrWild<'p, Cx> { /// `other_ctor` can be different from `self.ctor`, but must be covered by it. pub(crate) fn specialize( &self, - pcx: &PlaceCtxt<'_, 'p, Cx>, other_ctor: &Constructor<Cx>, - ctor_sub_tys: &[Cx::Ty], + ctor_arity: usize, ) -> SmallVec<[PatOrWild<'p, Cx>; 2]> { match self { - Wild => ctor_sub_tys.iter().map(|_| Wild).collect(), - Pat(pat) => pat.specialize(pcx, other_ctor, ctor_sub_tys), + Wild => (0..ctor_arity).map(|_| Wild).collect(), + Pat(pat) => pat.specialize(other_ctor, ctor_arity), } } diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs index 517d68115b7..ca6d8be2930 100644 --- a/compiler/rustc_pattern_analysis/src/usefulness.rs +++ b/compiler/rustc_pattern_analysis/src/usefulness.rs @@ -869,14 +869,13 @@ impl<'p, Cx: TypeCx> PatStack<'p, Cx> { /// Only call if `ctor.is_covered_by(self.head().ctor())` is true. fn pop_head_constructor( &self, - pcx: &PlaceCtxt<'_, 'p, Cx>, ctor: &Constructor<Cx>, - ctor_sub_tys: &[Cx::Ty], + ctor_arity: usize, ctor_is_relevant: bool, ) -> PatStack<'p, Cx> { // We pop the head pattern and push the new fields extracted from the arguments of // `self.head()`. - let mut new_pats = self.head().specialize(pcx, ctor, ctor_sub_tys); + let mut new_pats = self.head().specialize(ctor, ctor_arity); new_pats.extend_from_slice(&self.pats[1..]); // `ctor` is relevant for this row if it is the actual constructor of this row, or if the // row has a wildcard and `ctor` is relevant for wildcards. @@ -946,14 +945,13 @@ impl<'p, Cx: TypeCx> MatrixRow<'p, Cx> { /// Only call if `ctor.is_covered_by(self.head().ctor())` is true. fn pop_head_constructor( &self, - pcx: &PlaceCtxt<'_, 'p, Cx>, ctor: &Constructor<Cx>, - ctor_sub_tys: &[Cx::Ty], + ctor_arity: usize, ctor_is_relevant: bool, parent_row: usize, ) -> MatrixRow<'p, Cx> { MatrixRow { - pats: self.pats.pop_head_constructor(pcx, ctor, ctor_sub_tys, ctor_is_relevant), + pats: self.pats.pop_head_constructor(ctor, ctor_arity, ctor_is_relevant), parent_row, is_under_guard: self.is_under_guard, useful: false, @@ -1063,11 +1061,12 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> { ctor_is_relevant: bool, ) -> Matrix<'p, Cx> { let ctor_sub_tys = pcx.ctor_sub_tys(ctor); + let arity = ctor_sub_tys.len(); let specialized_place_ty = ctor_sub_tys.iter().chain(self.place_ty[1..].iter()).copied().collect(); let ctor_sub_validity = self.place_validity[0].specialize(ctor); let specialized_place_validity = std::iter::repeat(ctor_sub_validity) - .take(ctor.arity(pcx)) + .take(arity) .chain(self.place_validity[1..].iter().copied()) .collect(); let mut matrix = Matrix { @@ -1078,8 +1077,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> { }; for (i, row) in self.rows().enumerate() { if ctor.is_covered_by(pcx, row.head().ctor()) { - let new_row = - row.pop_head_constructor(pcx, ctor, ctor_sub_tys, ctor_is_relevant, i); + let new_row = row.pop_head_constructor(ctor, arity, ctor_is_relevant, i); matrix.expand_and_push(new_row); } } |
