@@ -1319,28 +1319,16 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
13191319 fn apply_constructor (
13201320 & mut self ,
13211321 pcx : & PlaceCtxt < ' _ , Cx > ,
1322- mut missing_ctors : & [ Constructor < Cx > ] ,
1322+ missing_ctors : & [ Constructor < Cx > ] ,
13231323 ctor : & Constructor < Cx > ,
1324- report_individual_missing_ctors : bool ,
13251324 ) {
13261325 if self . is_empty ( ) {
13271326 return ;
13281327 }
13291328 if matches ! ( ctor, Constructor :: Missing ) {
13301329 // We got the special `Missing` constructor that stands for the constructors not present
1331- // in the match.
1332- if !missing_ctors. is_empty ( ) && !report_individual_missing_ctors {
1333- // Report `_` as missing.
1334- missing_ctors = & [ Constructor :: Wildcard ] ;
1335- } else if missing_ctors. iter ( ) . any ( |c| c. is_non_exhaustive ( ) ) {
1336- // We need to report a `_` anyway, so listing other constructors would be redundant.
1337- // `NonExhaustive` is displayed as `_` just like `Wildcard`, but it will be picked
1338- // up by diagnostics to add a note about why `_` is required here.
1339- missing_ctors = & [ Constructor :: NonExhaustive ] ;
1340- }
1341-
1342- // For each missing constructor `c`, we add a `c(_, _, _)` witness appropriately
1343- // filled with wildcards.
1330+ // in the match. For each missing constructor `c`, we add a `c(_, _, _)` witness
1331+ // appropriately filled with wildcards.
13441332 let mut ret = Self :: empty ( ) ;
13451333 for ctor in missing_ctors {
13461334 let pat = pcx. wild_from_ctor ( ctor. clone ( ) ) ;
@@ -1515,9 +1503,6 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15151503 split_ctors. push ( Constructor :: Missing ) ;
15161504 }
15171505
1518- // Whether we should report "Enum::A and Enum::C are missing" or "_ is missing". At the top
1519- // level we prefer to list all constructors.
1520- let report_individual_missing_ctors = place. is_scrutinee || !all_missing;
15211506 // Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
15221507 // split_ctors.contains(Missing)`. The converse usually holds except when
15231508 // `!place_validity.is_known_valid()`.
@@ -1526,6 +1511,19 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15261511 missing_ctors. append ( & mut split_set. missing_empty ) ;
15271512 }
15281513
1514+ // Whether we should report "Enum::A and Enum::C are missing" or "_ is missing". At the top
1515+ // level we prefer to list all constructors.
1516+ let report_individual_missing_ctors = place. is_scrutinee || !all_missing;
1517+ if !missing_ctors. is_empty ( ) && !report_individual_missing_ctors {
1518+ // Report `_` as missing.
1519+ missing_ctors = vec ! [ Constructor :: Wildcard ] ;
1520+ } else if missing_ctors. iter ( ) . any ( |c| c. is_non_exhaustive ( ) ) {
1521+ // We need to report a `_` anyway, so listing other constructors would be redundant.
1522+ // `NonExhaustive` is displayed as `_` just like `Wildcard`, but it will be picked
1523+ // up by diagnostics to add a note about why `_` is required here.
1524+ missing_ctors = vec ! [ Constructor :: NonExhaustive ] ;
1525+ }
1526+
15291527 let mut ret = WitnessMatrix :: empty ( ) ;
15301528 for ctor in split_ctors {
15311529 // Dig into rows that match `ctor`.
@@ -1540,7 +1538,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15401538 } ) ?;
15411539
15421540 // Transform witnesses for `spec_matrix` into witnesses for `matrix`.
1543- witnesses. apply_constructor ( pcx, & missing_ctors, & ctor, report_individual_missing_ctors ) ;
1541+ witnesses. apply_constructor ( pcx, & missing_ctors, & ctor) ;
15441542 // Accumulate the found witnesses.
15451543 ret. extend ( witnesses) ;
15461544
0 commit comments