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