@@ -1363,23 +1363,19 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1363
1363
is_top_level && matches ! ( ctors_for_ty, ConstructorSet :: NoConstructors ) ;
1364
1364
// Whether empty patterns can be omitted for exhaustiveness.
1365
1365
let can_omit_empty_arms = is_toplevel_exception || mcx. tycx . is_exhaustive_patterns_feature_on ( ) ;
1366
+ // Whether empty patterns are counted as useful or not.
1367
+ let empty_arms_are_unreachable = place_validity. is_known_valid ( ) && can_omit_empty_arms;
1366
1368
1367
1369
// Analyze the constructors present in this column.
1368
1370
let ctors = matrix. heads ( ) . map ( |p| p. ctor ( ) ) ;
1369
1371
let mut split_set = ctors_for_ty. split ( ctors) ;
1370
- if !can_omit_empty_arms {
1371
- // Treat all missing constructors as nonempty.
1372
- // This clears `missing_empty`.
1373
- split_set. missing . append ( & mut split_set. missing_empty ) ;
1374
- }
1375
1372
let all_missing = split_set. present . is_empty ( ) ;
1376
-
1377
1373
// Build the set of constructors we will specialize with. It must cover the whole type.
1378
1374
// We need to iterate over a full set of constructors, so we add `Missing` to represent the
1379
1375
// missing ones. This is explained under "Constructor Splitting" at the top of this file.
1380
1376
let mut split_ctors = split_set. present ;
1381
1377
if !( split_set. missing . is_empty ( )
1382
- && ( split_set. missing_empty . is_empty ( ) || place_validity . is_known_valid ( ) ) )
1378
+ && ( split_set. missing_empty . is_empty ( ) || empty_arms_are_unreachable ) )
1383
1379
{
1384
1380
split_ctors. push ( Constructor :: Missing ) ;
1385
1381
}
@@ -1392,7 +1388,10 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1392
1388
// Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
1393
1389
// split_ctors.contains(Missing)`. The converse usually holds except when
1394
1390
// `!place_validity.is_known_valid()`.
1395
- let missing_ctors = split_set. missing ;
1391
+ let mut missing_ctors = split_set. missing ;
1392
+ if !can_omit_empty_arms {
1393
+ missing_ctors. append ( & mut split_set. missing_empty ) ;
1394
+ }
1396
1395
1397
1396
let mut ret = WitnessMatrix :: empty ( ) ;
1398
1397
for ctor in split_ctors {
0 commit comments