Skip to content

Commit 8ff893f

Browse files
committed
We only need the arity of the subtype list now
1 parent e139724 commit 8ff893f

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

compiler/rustc_pattern_analysis/src/lints.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
8888
(0..arity).map(|_| Self { patterns: Vec::new() }).collect();
8989
let relevant_patterns =
9090
self.patterns.iter().filter(|pat| ctor.is_covered_by(pcx, pat.ctor()));
91-
let ctor_sub_tys = pcx.ctor_sub_tys(ctor);
9291
for pat in relevant_patterns {
93-
let specialized = pat.specialize(pcx, ctor, ctor_sub_tys);
92+
let specialized = pat.specialize(ctor, arity);
9493
for (subpat, column) in specialized.into_iter().zip(&mut specialized_columns) {
9594
column.expand_and_push(subpat);
9695
}

compiler/rustc_pattern_analysis/src/pat.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> {
7272
/// `other_ctor` can be different from `self.ctor`, but must be covered by it.
7373
pub(crate) fn specialize(
7474
&self,
75-
_pcx: &PlaceCtxt<'_, 'p, Cx>,
7675
other_ctor: &Constructor<Cx>,
77-
ctor_sub_tys: &[Cx::Ty],
76+
ctor_arity: usize,
7877
) -> SmallVec<[PatOrWild<'p, Cx>; 2]> {
79-
let wildcard_sub_tys = || ctor_sub_tys.iter().map(|_| Wild).collect();
78+
let wildcard_sub_tys = || (0..ctor_arity).map(|_| Wild).collect();
8079
match (&self.ctor, other_ctor) {
8180
// Return a wildcard for each field of `other_ctor`.
8281
(Wildcard, _) => wildcard_sub_tys(),
@@ -192,13 +191,12 @@ impl<'p, Cx: TypeCx> PatOrWild<'p, Cx> {
192191
/// `other_ctor` can be different from `self.ctor`, but must be covered by it.
193192
pub(crate) fn specialize(
194193
&self,
195-
pcx: &PlaceCtxt<'_, 'p, Cx>,
196194
other_ctor: &Constructor<Cx>,
197-
ctor_sub_tys: &[Cx::Ty],
195+
ctor_arity: usize,
198196
) -> SmallVec<[PatOrWild<'p, Cx>; 2]> {
199197
match self {
200-
Wild => ctor_sub_tys.iter().map(|_| Wild).collect(),
201-
Pat(pat) => pat.specialize(pcx, other_ctor, ctor_sub_tys),
198+
Wild => (0..ctor_arity).map(|_| Wild).collect(),
199+
Pat(pat) => pat.specialize(other_ctor, ctor_arity),
202200
}
203201
}
204202

compiler/rustc_pattern_analysis/src/usefulness.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -869,14 +869,13 @@ impl<'p, Cx: TypeCx> PatStack<'p, Cx> {
869869
/// Only call if `ctor.is_covered_by(self.head().ctor())` is true.
870870
fn pop_head_constructor(
871871
&self,
872-
pcx: &PlaceCtxt<'_, 'p, Cx>,
873872
ctor: &Constructor<Cx>,
874-
ctor_sub_tys: &[Cx::Ty],
873+
ctor_arity: usize,
875874
ctor_is_relevant: bool,
876875
) -> PatStack<'p, Cx> {
877876
// We pop the head pattern and push the new fields extracted from the arguments of
878877
// `self.head()`.
879-
let mut new_pats = self.head().specialize(pcx, ctor, ctor_sub_tys);
878+
let mut new_pats = self.head().specialize(ctor, ctor_arity);
880879
new_pats.extend_from_slice(&self.pats[1..]);
881880
// `ctor` is relevant for this row if it is the actual constructor of this row, or if the
882881
// row has a wildcard and `ctor` is relevant for wildcards.
@@ -946,14 +945,13 @@ impl<'p, Cx: TypeCx> MatrixRow<'p, Cx> {
946945
/// Only call if `ctor.is_covered_by(self.head().ctor())` is true.
947946
fn pop_head_constructor(
948947
&self,
949-
pcx: &PlaceCtxt<'_, 'p, Cx>,
950948
ctor: &Constructor<Cx>,
951-
ctor_sub_tys: &[Cx::Ty],
949+
ctor_arity: usize,
952950
ctor_is_relevant: bool,
953951
parent_row: usize,
954952
) -> MatrixRow<'p, Cx> {
955953
MatrixRow {
956-
pats: self.pats.pop_head_constructor(pcx, ctor, ctor_sub_tys, ctor_is_relevant),
954+
pats: self.pats.pop_head_constructor(ctor, ctor_arity, ctor_is_relevant),
957955
parent_row,
958956
is_under_guard: self.is_under_guard,
959957
useful: false,
@@ -1063,11 +1061,12 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10631061
ctor_is_relevant: bool,
10641062
) -> Matrix<'p, Cx> {
10651063
let ctor_sub_tys = pcx.ctor_sub_tys(ctor);
1064+
let arity = ctor_sub_tys.len();
10661065
let specialized_place_ty =
10671066
ctor_sub_tys.iter().chain(self.place_ty[1..].iter()).copied().collect();
10681067
let ctor_sub_validity = self.place_validity[0].specialize(ctor);
10691068
let specialized_place_validity = std::iter::repeat(ctor_sub_validity)
1070-
.take(ctor.arity(pcx))
1069+
.take(arity)
10711070
.chain(self.place_validity[1..].iter().copied())
10721071
.collect();
10731072
let mut matrix = Matrix {
@@ -1078,8 +1077,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10781077
};
10791078
for (i, row) in self.rows().enumerate() {
10801079
if ctor.is_covered_by(pcx, row.head().ctor()) {
1081-
let new_row =
1082-
row.pop_head_constructor(pcx, ctor, ctor_sub_tys, ctor_is_relevant, i);
1080+
let new_row = row.pop_head_constructor(ctor, arity, ctor_is_relevant, i);
10831081
matrix.expand_and_push(new_row);
10841082
}
10851083
}

0 commit comments

Comments
 (0)