@@ -736,15 +736,13 @@ pub(crate) struct PlaceCtxt<'a, 'p, Cx: TypeCx> {
736
736
pub ( crate ) mcx : MatchCtxt < ' a , ' p , Cx > ,
737
737
/// Type of the place under investigation.
738
738
pub ( crate ) ty : Cx :: Ty ,
739
- /// Whether the place is the original scrutinee place, as opposed to a subplace of it.
740
- pub ( crate ) is_scrutinee : bool ,
741
739
}
742
740
743
741
impl < ' a , ' p , Cx : TypeCx > PlaceCtxt < ' a , ' p , Cx > {
744
742
/// A `PlaceCtxt` when code other than `is_useful` needs one.
745
743
#[ cfg_attr( not( feature = "rustc" ) , allow( dead_code) ) ]
746
744
pub ( crate ) fn new_dummy ( mcx : MatchCtxt < ' a , ' p , Cx > , ty : Cx :: Ty ) -> Self {
747
- PlaceCtxt { mcx, ty, is_scrutinee : false }
745
+ PlaceCtxt { mcx, ty }
748
746
}
749
747
750
748
pub ( crate ) fn ctor_arity ( & self , ctor : & Constructor < Cx > ) -> usize {
@@ -1360,7 +1358,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1360
1358
} ;
1361
1359
1362
1360
debug ! ( "ty: {ty:?}" ) ;
1363
- let pcx = & PlaceCtxt { mcx, ty, is_scrutinee : is_top_level } ;
1361
+ let pcx = & PlaceCtxt { mcx, ty } ;
1364
1362
1365
1363
// Whether the place/column we are inspecting is known to contain valid data.
1366
1364
let place_validity = matrix. place_validity [ 0 ] ;
@@ -1369,7 +1367,17 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1369
1367
let ctors = matrix. heads ( ) . map ( |p| p. ctor ( ) ) ;
1370
1368
let ctors_for_ty = pcx. ctors_for_ty ( ) ;
1371
1369
let is_integers = matches ! ( ctors_for_ty, ConstructorSet :: Integers { .. } ) ; // For diagnostics.
1372
- let split_set = ctors_for_ty. split ( pcx, ctors) ;
1370
+ let mut split_set = ctors_for_ty. split ( ctors) ;
1371
+ // We have now grouped all the constructors into 3 buckets: present, missing, missing_empty.
1372
+ // In the absence of the `exhaustive_patterns` feature however, we don't count nested empty
1373
+ // types as empty. Only non-nested `!` or `enum Foo {}` are considered empty.
1374
+ if !pcx. mcx . tycx . is_exhaustive_patterns_feature_on ( )
1375
+ && !( is_top_level && matches ! ( ctors_for_ty, ConstructorSet :: NoConstructors ) )
1376
+ {
1377
+ // Treat all missing constructors as nonempty.
1378
+ // This clears `missing_empty`.
1379
+ split_set. missing . append ( & mut split_set. missing_empty ) ;
1380
+ }
1373
1381
let all_missing = split_set. present . is_empty ( ) ;
1374
1382
1375
1383
// Build the set of constructors we will specialize with. It must cover the whole type.
0 commit comments