@@ -1047,22 +1047,17 @@ impl<'a, Ty> TyLayout<'a, Ty> {
10471047 /// FIXME: Once we removed all the conservatism, we could alternatively
10481048 /// create an all-0/all-undef constant and run the vonst value validator to see if
10491049 /// this is a valid value for the given type.
1050- pub fn might_permit_raw_init < C , E > (
1051- self ,
1052- cx : & C ,
1053- zero : bool ,
1054- ) -> Result < bool , E >
1050+ pub fn might_permit_raw_init < C , E > ( self , cx : & C , zero : bool ) -> Result < bool , E >
10551051 where
10561052 Self : Copy ,
10571053 Ty : TyLayoutMethods < ' a , C > ,
1058- C : LayoutOf < Ty = Ty , TyLayout : MaybeResult < Self , Error = E > > + HasDataLayout
1054+ C : LayoutOf < Ty = Ty , TyLayout : MaybeResult < Self , Error = E > > + HasDataLayout ,
10591055 {
10601056 let scalar_allows_raw_init = move |s : & Scalar | -> bool {
10611057 if zero {
10621058 let range = & s. valid_range ;
10631059 // The range must contain 0.
1064- range. contains ( & 0 ) ||
1065- ( * range. start ( ) > * range. end ( ) ) // wrap-around allows 0
1060+ range. contains ( & 0 ) || ( * range. start ( ) > * range. end ( ) ) // wrap-around allows 0
10661061 } else {
10671062 // The range must include all values. `valid_range_exclusive` handles
10681063 // the wrap-around using target arithmetic; with wrap-around then the full
@@ -1076,13 +1071,11 @@ impl<'a, Ty> TyLayout<'a, Ty> {
10761071 let res = match & self . abi {
10771072 Abi :: Uninhabited => false , // definitely UB
10781073 Abi :: Scalar ( s) => scalar_allows_raw_init ( s) ,
1079- Abi :: ScalarPair ( s1, s2) =>
1080- scalar_allows_raw_init ( s1) && scalar_allows_raw_init ( s2) ,
1081- Abi :: Vector { element : s, count } =>
1082- * count == 0 || scalar_allows_raw_init ( s) ,
1074+ Abi :: ScalarPair ( s1, s2) => scalar_allows_raw_init ( s1) && scalar_allows_raw_init ( s2) ,
1075+ Abi :: Vector { element : s, count } => * count == 0 || scalar_allows_raw_init ( s) ,
10831076 Abi :: Aggregate { .. } => {
10841077 match self . variants {
1085- Variants :: Multiple { .. } =>
1078+ Variants :: Multiple { .. } => {
10861079 if zero {
10871080 // FIXME(#66151):
10881081 // could we identify the variant with discriminant 0, check that?
@@ -1091,17 +1084,20 @@ impl<'a, Ty> TyLayout<'a, Ty> {
10911084 // FIXME(#66151): This needs to have some sort of discriminant,
10921085 // which cannot be undef. But for now we are conservative.
10931086 true
1094- } ,
1087+ }
1088+ }
10951089 Variants :: Single { .. } => {
10961090 // For aggregates, recurse.
10971091 match self . fields {
10981092 FieldPlacement :: Union ( ..) => true , // An all-0 unit is fine.
10991093 FieldPlacement :: Array { .. } =>
1100- // FIXME(#66151): The widely use smallvec 0.6 creates uninit arrays
1101- // with any element type, so let us not (yet) complain about that.
1102- /* count == 0 ||
1103- self.field(cx, 0).to_result()?.might_permit_raw_init(cx, zero)? */
1104- true ,
1094+ // FIXME(#66151): The widely use smallvec 0.6 creates uninit arrays
1095+ // with any element type, so let us not (yet) complain about that.
1096+ /* count == 0 ||
1097+ self.field(cx, 0).to_result()?.might_permit_raw_init(cx, zero)? */
1098+ {
1099+ true
1100+ }
11051101 FieldPlacement :: Arbitrary { .. } => {
11061102 // FIXME(#66151) cargo depends on sized-chunks 0.3.0 which
11071103 // has some illegal zero-initialization, so let us not (yet)
0 commit comments