@@ -11,6 +11,24 @@ use crate::{
1111 Variants , WrappingRange ,
1212} ;
1313
14+ // A variant is absent if it's uninhabited and only has ZST fields.
15+ // Present uninhabited variants only require space for their fields,
16+ // but *not* an encoding of the discriminant (e.g., a tag value).
17+ // See issue #49298 for more details on the need to leave space
18+ // for non-ZST uninhabited data (mostly partial initialization).
19+ fn absent < ' a , FieldIdx , VariantIdx , F > ( fields : & IndexSlice < FieldIdx , F > ) -> bool
20+ where
21+ FieldIdx : Idx ,
22+ VariantIdx : Idx ,
23+ F : Deref < Target = & ' a LayoutS < FieldIdx , VariantIdx > > + fmt:: Debug ,
24+ {
25+ let uninhabited = fields. iter ( ) . any ( |f| f. abi . is_uninhabited ( ) ) ;
26+ // We cannot ignore alignment; that might lead us to entirely discard a variant and
27+ // produce an enum that is less aligned than it should be!
28+ let is_1zst = fields. iter ( ) . all ( |f| f. is_1zst ( ) ) ;
29+ uninhabited && is_1zst
30+ }
31+
1432pub trait LayoutCalculator {
1533 type TargetDataLayoutRef : Borrow < TargetDataLayout > ;
1634
@@ -168,18 +186,6 @@ pub trait LayoutCalculator {
168186 Scalar :: Initialized { value, valid_range : WrappingRange :: full ( size) }
169187 } ;
170188
171- // A variant is absent if it's uninhabited and only has ZST fields.
172- // Present uninhabited variants only require space for their fields,
173- // but *not* an encoding of the discriminant (e.g., a tag value).
174- // See issue #49298 for more details on the need to leave space
175- // for non-ZST uninhabited data (mostly partial initialization).
176- let absent = |fields : & IndexSlice < FieldIdx , F > | {
177- let uninhabited = fields. iter ( ) . any ( |f| f. abi . is_uninhabited ( ) ) ;
178- // We cannot ignore alignment; that might lead us to entirely discard a variant and
179- // produce an enum that is less aligned than it should be!
180- let is_1zst = fields. iter ( ) . all ( |f| f. is_1zst ( ) ) ;
181- uninhabited && is_1zst
182- } ;
183189 let ( present_first, present_second) = {
184190 let mut present_variants = variants
185191 . iter_enumerated ( )
0 commit comments