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