@@ -817,6 +817,9 @@ impl fmt::Display for ValidityConstraint {
817
817
struct PlaceInfo < Cx : TypeCx > {
818
818
/// The type of the place.
819
819
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 ,
820
823
/// Whether the place is known to contain valid data.
821
824
validity : ValidityConstraint ,
822
825
/// Whether the place is the scrutinee itself or a subplace of it.
@@ -833,10 +836,9 @@ impl<Cx: TypeCx> PlaceInfo<Cx> {
833
836
) -> impl Iterator < Item = Self > + ExactSizeIterator + Captures < ' a > {
834
837
let ctor_sub_tys = cx. ctor_sub_tys ( ctor, & self . ty ) ;
835
838
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 {
839
840
ty,
841
+ skip,
840
842
validity : ctor_sub_validity,
841
843
is_scrutinee : false ,
842
844
} )
@@ -858,6 +860,11 @@ impl<Cx: TypeCx> PlaceInfo<Cx> {
858
860
where
859
861
Cx : ' a ,
860
862
{
863
+ if matches ! ( self . skip, SkipField ( true ) ) {
864
+ // Skip the whole column
865
+ return Ok ( ( smallvec ! [ Constructor :: Skip ] , vec ! [ ] ) ) ;
866
+ }
867
+
861
868
let ctors_for_ty = cx. ctors_for_ty ( & self . ty ) ?;
862
869
863
870
// We treat match scrutinees of type `!` or `EmptyEnum` differently.
@@ -916,7 +923,12 @@ impl<Cx: TypeCx> PlaceInfo<Cx> {
916
923
917
924
impl < Cx : TypeCx > Clone for PlaceInfo < Cx > {
918
925
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
+ }
920
932
}
921
933
}
922
934
@@ -1123,7 +1135,12 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
1123
1135
scrut_ty : Cx :: Ty ,
1124
1136
scrut_validity : ValidityConstraint ,
1125
1137
) -> 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
+ } ;
1127
1144
let mut matrix = Matrix {
1128
1145
rows : Vec :: with_capacity ( arms. len ( ) ) ,
1129
1146
place_info : smallvec ! [ place_info] ,
0 commit comments