@@ -1363,23 +1363,19 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
13631363 is_top_level && matches ! ( ctors_for_ty, ConstructorSet :: NoConstructors ) ;
13641364 // Whether empty patterns can be omitted for exhaustiveness.
13651365 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;
13661368
13671369 // Analyze the constructors present in this column.
13681370 let ctors = matrix. heads ( ) . map ( |p| p. ctor ( ) ) ;
13691371 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- }
13751372 let all_missing = split_set. present . is_empty ( ) ;
1376-
13771373 // Build the set of constructors we will specialize with. It must cover the whole type.
13781374 // We need to iterate over a full set of constructors, so we add `Missing` to represent the
13791375 // missing ones. This is explained under "Constructor Splitting" at the top of this file.
13801376 let mut split_ctors = split_set. present ;
13811377 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 ) )
13831379 {
13841380 split_ctors. push ( Constructor :: Missing ) ;
13851381 }
@@ -1392,7 +1388,10 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
13921388 // Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
13931389 // split_ctors.contains(Missing)`. The converse usually holds except when
13941390 // `!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+ }
13961395
13971396 let mut ret = WitnessMatrix :: empty ( ) ;
13981397 for ctor in split_ctors {
0 commit comments