@@ -1441,23 +1441,19 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14411441 is_top_level && matches ! ( ctors_for_ty, ConstructorSet :: NoConstructors ) ;
14421442 // Whether empty patterns can be omitted for exhaustiveness.
14431443 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;
14441446
14451447 // Analyze the constructors present in this column.
14461448 let ctors = matrix. heads ( ) . map ( |p| p. ctor ( ) ) ;
14471449 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- }
14531450 let all_missing = split_set. present . is_empty ( ) ;
1454-
14551451 // Build the set of constructors we will specialize with. It must cover the whole type.
14561452 // We need to iterate over a full set of constructors, so we add `Missing` to represent the
14571453 // missing ones. This is explained under "Constructor Splitting" at the top of this file.
14581454 let mut split_ctors = split_set. present ;
14591455 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 ) )
14611457 {
14621458 split_ctors. push ( Constructor :: Missing ) ;
14631459 }
@@ -1470,7 +1466,10 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14701466 // Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
14711467 // split_ctors.contains(Missing)`. The converse usually holds except when
14721468 // `!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+ }
14741473
14751474 let mut ret = WitnessMatrix :: empty ( ) ;
14761475 for ctor in split_ctors {
0 commit comments