Skip to content

Commit 5ffef0c

Browse files
committed
Tweak how we record missing constructors
This is slower but also not a performance-sensitive path.
1 parent 0a5b998 commit 5ffef0c

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

compiler/rustc_pattern_analysis/src/usefulness.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
13121312
fn apply_constructor(
13131313
&mut self,
13141314
pcx: &PlaceCtxt<'_, Cx>,
1315-
missing_ctors: &[Constructor<Cx>],
1315+
mut missing_ctors: &[Constructor<Cx>],
13161316
ctor: &Constructor<Cx>,
13171317
report_individual_missing_ctors: bool,
13181318
) {
@@ -1322,32 +1322,27 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
13221322
if matches!(ctor, Constructor::Missing) {
13231323
// We got the special `Missing` constructor that stands for the constructors not present
13241324
// in the match.
1325-
if missing_ctors.is_empty() {
1326-
// Nothing to report.
1327-
*self = Self::empty();
1328-
} else if !report_individual_missing_ctors {
1325+
if !missing_ctors.is_empty() && !report_individual_missing_ctors {
13291326
// Report `_` as missing.
1330-
let pat = pcx.wild_from_ctor(Constructor::Wildcard);
1331-
self.push_pattern(pat);
1327+
missing_ctors = &[Constructor::Wildcard];
13321328
} else if missing_ctors.iter().any(|c| c.is_non_exhaustive()) {
13331329
// We need to report a `_` anyway, so listing other constructors would be redundant.
13341330
// `NonExhaustive` is displayed as `_` just like `Wildcard`, but it will be picked
13351331
// up by diagnostics to add a note about why `_` is required here.
1336-
let pat = pcx.wild_from_ctor(Constructor::NonExhaustive);
1337-
self.push_pattern(pat);
1338-
} else {
1339-
// For each missing constructor `c`, we add a `c(_, _, _)` witness appropriately
1340-
// filled with wildcards.
1341-
let mut ret = Self::empty();
1342-
for ctor in missing_ctors {
1343-
let pat = pcx.wild_from_ctor(ctor.clone());
1344-
// Clone `self` and add `c(_, _, _)` to each of its witnesses.
1345-
let mut wit_matrix = self.clone();
1346-
wit_matrix.push_pattern(pat);
1347-
ret.extend(wit_matrix);
1348-
}
1349-
*self = ret;
1332+
missing_ctors = &[Constructor::NonExhaustive];
1333+
}
1334+
1335+
// For each missing constructor `c`, we add a `c(_, _, _)` witness appropriately
1336+
// filled with wildcards.
1337+
let mut ret = Self::empty();
1338+
for ctor in missing_ctors {
1339+
let pat = pcx.wild_from_ctor(ctor.clone());
1340+
// Clone `self` and add `c(_, _, _)` to each of its witnesses.
1341+
let mut wit_matrix = self.clone();
1342+
wit_matrix.push_pattern(pat);
1343+
ret.extend(wit_matrix);
13501344
}
1345+
*self = ret;
13511346
} else {
13521347
// Any other constructor we unspecialize as expected.
13531348
for witness in self.0.iter_mut() {

0 commit comments

Comments
 (0)