@@ -737,15 +737,13 @@ pub(crate) struct PlaceCtxt<'a, Cx: TypeCx> {
737
737
pub ( crate ) mcx : MatchCtxt < ' a , Cx > ,
738
738
/// Type of the place under investigation.
739
739
pub ( crate ) ty : Cx :: Ty ,
740
- /// Whether the place is the original scrutinee place, as opposed to a subplace of it.
741
- pub ( crate ) is_scrutinee : bool ,
742
740
}
743
741
744
742
impl < ' a , Cx : TypeCx > PlaceCtxt < ' a , Cx > {
745
743
/// A `PlaceCtxt` when code other than `is_useful` needs one.
746
744
#[ cfg_attr( not( feature = "rustc" ) , allow( dead_code) ) ]
747
745
pub ( crate ) fn new_dummy ( mcx : MatchCtxt < ' a , Cx > , ty : Cx :: Ty ) -> Self {
748
- PlaceCtxt { mcx, ty, is_scrutinee : false }
746
+ PlaceCtxt { mcx, ty }
749
747
}
750
748
751
749
pub ( crate ) fn ctor_arity ( & self , ctor : & Constructor < Cx > ) -> usize {
@@ -1442,7 +1440,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1442
1440
} ;
1443
1441
1444
1442
debug ! ( "ty: {ty:?}" ) ;
1445
- let pcx = & PlaceCtxt { mcx, ty, is_scrutinee : is_top_level } ;
1443
+ let pcx = & PlaceCtxt { mcx, ty } ;
1446
1444
1447
1445
// Whether the place/column we are inspecting is known to contain valid data.
1448
1446
let place_validity = matrix. place_validity [ 0 ] ;
@@ -1451,7 +1449,17 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1451
1449
let ctors = matrix. heads ( ) . map ( |p| p. ctor ( ) ) ;
1452
1450
let ctors_for_ty = pcx. ctors_for_ty ( ) ?;
1453
1451
let is_integers = matches ! ( ctors_for_ty, ConstructorSet :: Integers { .. } ) ; // For diagnostics.
1454
- let split_set = ctors_for_ty. split ( pcx, ctors) ;
1452
+ let mut split_set = ctors_for_ty. split ( ctors) ;
1453
+ // We have now grouped all the constructors into 3 buckets: present, missing, missing_empty.
1454
+ // In the absence of the `exhaustive_patterns` feature however, we don't count nested empty
1455
+ // types as empty. Only non-nested `!` or `enum Foo {}` are considered empty.
1456
+ if !pcx. mcx . tycx . is_exhaustive_patterns_feature_on ( )
1457
+ && !( is_top_level && matches ! ( ctors_for_ty, ConstructorSet :: NoConstructors ) )
1458
+ {
1459
+ // Treat all missing constructors as nonempty.
1460
+ // This clears `missing_empty`.
1461
+ split_set. missing . append ( & mut split_set. missing_empty ) ;
1462
+ }
1455
1463
let all_missing = split_set. present . is_empty ( ) ;
1456
1464
1457
1465
// Build the set of constructors we will specialize with. It must cover the whole type.
0 commit comments