@@ -1312,28 +1312,16 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
13121312 fn apply_constructor (
13131313 & mut self ,
13141314 pcx : & PlaceCtxt < ' _ , Cx > ,
1315- mut missing_ctors : & [ Constructor < Cx > ] ,
1315+ missing_ctors : & [ Constructor < Cx > ] ,
13161316 ctor : & Constructor < Cx > ,
1317- report_individual_missing_ctors : bool ,
13181317 ) {
13191318 if self . is_empty ( ) {
13201319 return ;
13211320 }
13221321 if matches ! ( ctor, Constructor :: Missing ) {
13231322 // We got the special `Missing` constructor that stands for the constructors not present
1324- // in the match.
1325- if !missing_ctors. is_empty ( ) && !report_individual_missing_ctors {
1326- // Report `_` as missing.
1327- missing_ctors = & [ Constructor :: Wildcard ] ;
1328- } else if missing_ctors. iter ( ) . any ( |c| c. is_non_exhaustive ( ) ) {
1329- // We need to report a `_` anyway, so listing other constructors would be redundant.
1330- // `NonExhaustive` is displayed as `_` just like `Wildcard`, but it will be picked
1331- // up by diagnostics to add a note about why `_` is required here.
1332- missing_ctors = & [ Constructor :: NonExhaustive ] ;
1333- }
1334-
1335- // For each missing constructor `c`, we add a `c(_, _, _)` witness appropriately
1336- // filled with wildcards.
1323+ // in the match. For each missing constructor `c`, we add a `c(_, _, _)` witness
1324+ // appropriately filled with wildcards.
13371325 let mut ret = Self :: empty ( ) ;
13381326 for ctor in missing_ctors {
13391327 let pat = pcx. wild_from_ctor ( ctor. clone ( ) ) ;
@@ -1508,9 +1496,6 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15081496 split_ctors. push ( Constructor :: Missing ) ;
15091497 }
15101498
1511- // Whether we should report "Enum::A and Enum::C are missing" or "_ is missing". At the top
1512- // level we prefer to list all constructors.
1513- let report_individual_missing_ctors = place. is_scrutinee || !all_missing;
15141499 // Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
15151500 // split_ctors.contains(Missing)`. The converse usually holds except when
15161501 // `!place_validity.is_known_valid()`.
@@ -1519,6 +1504,19 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15191504 missing_ctors. append ( & mut split_set. missing_empty ) ;
15201505 }
15211506
1507+ // Whether we should report "Enum::A and Enum::C are missing" or "_ is missing". At the top
1508+ // level we prefer to list all constructors.
1509+ let report_individual_missing_ctors = place. is_scrutinee || !all_missing;
1510+ if !missing_ctors. is_empty ( ) && !report_individual_missing_ctors {
1511+ // Report `_` as missing.
1512+ missing_ctors = vec ! [ Constructor :: Wildcard ] ;
1513+ } else if missing_ctors. iter ( ) . any ( |c| c. is_non_exhaustive ( ) ) {
1514+ // We need to report a `_` anyway, so listing other constructors would be redundant.
1515+ // `NonExhaustive` is displayed as `_` just like `Wildcard`, but it will be picked
1516+ // up by diagnostics to add a note about why `_` is required here.
1517+ missing_ctors = vec ! [ Constructor :: NonExhaustive ] ;
1518+ }
1519+
15221520 let mut ret = WitnessMatrix :: empty ( ) ;
15231521 for ctor in split_ctors {
15241522 // Dig into rows that match `ctor`.
@@ -1533,7 +1531,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15331531 } ) ?;
15341532
15351533 // Transform witnesses for `spec_matrix` into witnesses for `matrix`.
1536- witnesses. apply_constructor ( pcx, & missing_ctors, & ctor, report_individual_missing_ctors ) ;
1534+ witnesses. apply_constructor ( pcx, & missing_ctors, & ctor) ;
15371535 // Accumulate the found witnesses.
15381536 ret. extend ( witnesses) ;
15391537
0 commit comments