Skip to content

Commit 50b197c

Browse files
committed
Reuse ctor_sub_tys when we have one around
1 parent d40f1b1 commit 50b197c

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

compiler/rustc_pattern_analysis/src/lints.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
8383
(0..arity).map(|_| Self { patterns: Vec::new() }).collect();
8484
let relevant_patterns =
8585
self.patterns.iter().filter(|pat| ctor.is_covered_by(pcx, pat.ctor()));
86+
let ctor_sub_tys = pcx.ctor_sub_tys(ctor);
8687
for pat in relevant_patterns {
87-
let specialized = pat.specialize(pcx, ctor);
88+
let specialized = pat.specialize(pcx, ctor, ctor_sub_tys);
8889
for (subpat, column) in specialized.iter().zip(&mut specialized_columns) {
8990
if subpat.is_or_pat() {
9091
column.patterns.extend(subpat.flatten_or_pat())

compiler/rustc_pattern_analysis/src/pat.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> {
8181
&self,
8282
pcx: &PlaceCtxt<'_, 'p, Cx>,
8383
other_ctor: &Constructor<Cx>,
84+
ctor_sub_tys: &[Cx::Ty],
8485
) -> SmallVec<[&'p DeconstructedPat<'p, Cx>; 2]> {
8586
let wildcard_sub_tys = || {
86-
let tys = pcx.ctor_sub_tys(other_ctor);
87-
tys.iter()
87+
ctor_sub_tys
88+
.iter()
8889
.map(|ty| DeconstructedPat::wildcard(*ty))
8990
.map(|pat| pcx.mcx.wildcard_arena.alloc(pat) as &_)
9091
.collect()

compiler/rustc_pattern_analysis/src/usefulness.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -874,11 +874,12 @@ impl<'p, Cx: TypeCx> PatStack<'p, Cx> {
874874
&self,
875875
pcx: &PlaceCtxt<'_, 'p, Cx>,
876876
ctor: &Constructor<Cx>,
877+
ctor_sub_tys: &[Cx::Ty],
877878
ctor_is_relevant: bool,
878879
) -> PatStack<'p, Cx> {
879880
// We pop the head pattern and push the new fields extracted from the arguments of
880881
// `self.head()`.
881-
let mut new_pats = self.head().specialize(pcx, ctor);
882+
let mut new_pats = self.head().specialize(pcx, ctor, ctor_sub_tys);
882883
new_pats.extend_from_slice(&self.pats[1..]);
883884
// `ctor` is relevant for this row if it is the actual constructor of this row, or if the
884885
// row has a wildcard and `ctor` is relevant for wildcards.
@@ -950,11 +951,12 @@ impl<'p, Cx: TypeCx> MatrixRow<'p, Cx> {
950951
&self,
951952
pcx: &PlaceCtxt<'_, 'p, Cx>,
952953
ctor: &Constructor<Cx>,
954+
ctor_sub_tys: &[Cx::Ty],
953955
ctor_is_relevant: bool,
954956
parent_row: usize,
955957
) -> MatrixRow<'p, Cx> {
956958
MatrixRow {
957-
pats: self.pats.pop_head_constructor(pcx, ctor, ctor_is_relevant),
959+
pats: self.pats.pop_head_constructor(pcx, ctor, ctor_sub_tys, ctor_is_relevant),
958960
parent_row,
959961
is_under_guard: self.is_under_guard,
960962
useful: false,
@@ -1079,7 +1081,8 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10791081
};
10801082
for (i, row) in self.rows().enumerate() {
10811083
if ctor.is_covered_by(pcx, row.head().ctor()) {
1082-
let new_row = row.pop_head_constructor(pcx, ctor, ctor_is_relevant, i);
1084+
let new_row =
1085+
row.pop_head_constructor(pcx, ctor, ctor_sub_tys, ctor_is_relevant, i);
10831086
matrix.expand_and_push(new_row);
10841087
}
10851088
}

0 commit comments

Comments
 (0)