@@ -817,6 +817,9 @@ impl fmt::Display for ValidityConstraint {
817817struct PlaceInfo < Cx : TypeCx > {
818818 /// The type of the place.
819819 ty : Cx :: Ty ,
820+ /// Whether we must skip this field during analysis. This is used when a private field is empty,
821+ /// so that we don't observe its emptiness.
822+ skip : SkipField ,
820823 /// Whether the place is known to contain valid data.
821824 validity : ValidityConstraint ,
822825 /// Whether the place is the scrutinee itself or a subplace of it.
@@ -833,10 +836,9 @@ impl<Cx: TypeCx> PlaceInfo<Cx> {
833836 ) -> impl Iterator < Item = Self > + ExactSizeIterator + Captures < ' a > {
834837 let ctor_sub_tys = cx. ctor_sub_tys ( ctor, & self . ty ) ;
835838 let ctor_sub_validity = self . validity . specialize ( ctor) ;
836- // Collect to keep the `ExactSizeIterator` bound. This is a temporary measure.
837- let tmp: Vec < _ > = ctor_sub_tys. filter ( |( _, SkipField ( skip) ) | !skip) . collect ( ) ;
838- tmp. into_iter ( ) . map ( move |( ty, _) | PlaceInfo {
839+ ctor_sub_tys. map ( move |( ty, skip) | PlaceInfo {
839840 ty,
841+ skip,
840842 validity : ctor_sub_validity,
841843 is_scrutinee : false ,
842844 } )
@@ -858,6 +860,11 @@ impl<Cx: TypeCx> PlaceInfo<Cx> {
858860 where
859861 Cx : ' a ,
860862 {
863+ if matches ! ( self . skip, SkipField ( true ) ) {
864+ // Skip the whole column
865+ return Ok ( ( smallvec ! [ Constructor :: Skip ] , vec ! [ ] ) ) ;
866+ }
867+
861868 let ctors_for_ty = cx. ctors_for_ty ( & self . ty ) ?;
862869
863870 // We treat match scrutinees of type `!` or `EmptyEnum` differently.
@@ -916,7 +923,12 @@ impl<Cx: TypeCx> PlaceInfo<Cx> {
916923
917924impl < Cx : TypeCx > Clone for PlaceInfo < Cx > {
918925 fn clone ( & self ) -> Self {
919- Self { ty : self . ty . clone ( ) , validity : self . validity , is_scrutinee : self . is_scrutinee }
926+ Self {
927+ ty : self . ty . clone ( ) ,
928+ skip : self . skip ,
929+ validity : self . validity ,
930+ is_scrutinee : self . is_scrutinee ,
931+ }
920932 }
921933}
922934
@@ -1123,7 +1135,12 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
11231135 scrut_ty : Cx :: Ty ,
11241136 scrut_validity : ValidityConstraint ,
11251137 ) -> Self {
1126- let place_info = PlaceInfo { ty : scrut_ty, validity : scrut_validity, is_scrutinee : true } ;
1138+ let place_info = PlaceInfo {
1139+ ty : scrut_ty,
1140+ skip : SkipField ( false ) ,
1141+ validity : scrut_validity,
1142+ is_scrutinee : true ,
1143+ } ;
11271144 let mut matrix = Matrix {
11281145 rows : Vec :: with_capacity ( arms. len ( ) ) ,
11291146 place_info : smallvec ! [ place_info] ,
0 commit comments