@@ -1441,23 +1441,19 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1441
1441
is_top_level && matches ! ( ctors_for_ty, ConstructorSet :: NoConstructors ) ;
1442
1442
// Whether empty patterns can be omitted for exhaustiveness.
1443
1443
let can_omit_empty_arms = is_toplevel_exception || mcx. tycx . is_exhaustive_patterns_feature_on ( ) ;
1444
+ // Whether empty patterns are counted as useful or not.
1445
+ let empty_arms_are_unreachable = place_validity. is_known_valid ( ) && can_omit_empty_arms;
1444
1446
1445
1447
// Analyze the constructors present in this column.
1446
1448
let ctors = matrix. heads ( ) . map ( |p| p. ctor ( ) ) ;
1447
1449
let mut split_set = ctors_for_ty. split ( ctors) ;
1448
- if !can_omit_empty_arms {
1449
- // Treat all missing constructors as nonempty.
1450
- // This clears `missing_empty`.
1451
- split_set. missing . append ( & mut split_set. missing_empty ) ;
1452
- }
1453
1450
let all_missing = split_set. present . is_empty ( ) ;
1454
-
1455
1451
// Build the set of constructors we will specialize with. It must cover the whole type.
1456
1452
// We need to iterate over a full set of constructors, so we add `Missing` to represent the
1457
1453
// missing ones. This is explained under "Constructor Splitting" at the top of this file.
1458
1454
let mut split_ctors = split_set. present ;
1459
1455
if !( split_set. missing . is_empty ( )
1460
- && ( split_set. missing_empty . is_empty ( ) || place_validity . is_known_valid ( ) ) )
1456
+ && ( split_set. missing_empty . is_empty ( ) || empty_arms_are_unreachable ) )
1461
1457
{
1462
1458
split_ctors. push ( Constructor :: Missing ) ;
1463
1459
}
@@ -1470,7 +1466,10 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1470
1466
// Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
1471
1467
// split_ctors.contains(Missing)`. The converse usually holds except when
1472
1468
// `!place_validity.is_known_valid()`.
1473
- let missing_ctors = split_set. missing ;
1469
+ let mut missing_ctors = split_set. missing ;
1470
+ if !can_omit_empty_arms {
1471
+ missing_ctors. append ( & mut split_set. missing_empty ) ;
1472
+ }
1474
1473
1475
1474
let mut ret = WitnessMatrix :: empty ( ) ;
1476
1475
for ctor in split_ctors {
0 commit comments