@@ -1126,7 +1126,7 @@ impl<'a, Ty> TyLayout<'a, Ty> {
1126
1126
/// left entirely uninitialized.
1127
1127
/// This is conservative: in doubt, it will answer `true`.
1128
1128
pub fn might_permit_raw_init < C , E > (
1129
- & self ,
1129
+ self ,
1130
1130
cx : & C ,
1131
1131
zero : bool ,
1132
1132
) -> Result < bool , E >
@@ -1156,30 +1156,39 @@ impl<'a, Ty> TyLayout<'a, Ty> {
1156
1156
Abi :: Vector { element : s, count } =>
1157
1157
* count == 0 || scalar_allows_raw_init ( s) ,
1158
1158
Abi :: Aggregate { .. } => {
1159
- // For aggregates, recurse.
1160
- let inner = match self . variants {
1161
- Variants :: Multiple { .. } => // FIXME: could we be more precise here?
1162
- return Ok ( true ) ,
1163
- Variants :: Single { index } => self . for_variant ( & cx, index) ,
1164
- } ;
1165
-
1166
- match inner. fields {
1167
- FieldPlacement :: Union ( ..) => true , // An all-0 unit is fine.
1168
- FieldPlacement :: Array { .. } =>
1169
- // FIXME: The widely use smallvec 0.6 creates uninit arrays
1170
- // with any element type, so let us not (yet) complain about that.
1171
- // count == 0 ||
1172
- // inner.field(cx, 0).to_result()?.might_permit_raw_init(cx, zero)?
1173
- true ,
1174
- FieldPlacement :: Arbitrary { ref offsets, .. } => {
1175
- // Check that all fields accept zero-init.
1176
- for idx in 0 ..offsets. len ( ) {
1177
- if !inner. field ( cx, idx) . to_result ( ) ?. might_permit_raw_init ( cx, zero) ? {
1178
- return Ok ( false ) ;
1159
+ match self . variants {
1160
+ Variants :: Multiple { .. } =>
1161
+ if zero {
1162
+ // FIXME: could we identify the variant with discriminant 0, check that?
1163
+ true
1164
+ } else {
1165
+ // FIXME: This needs to have some sort of discriminant,
1166
+ // which cannot be undef. But for now we are conservative.
1167
+ true
1168
+ } ,
1169
+ Variants :: Single { .. } => {
1170
+ // For aggregates, recurse.
1171
+ match self . fields {
1172
+ FieldPlacement :: Union ( ..) => true , // An all-0 unit is fine.
1173
+ FieldPlacement :: Array { .. } =>
1174
+ // FIXME: The widely use smallvec 0.6 creates uninit arrays
1175
+ // with any element type, so let us not (yet) complain about that.
1176
+ // count == 0 ||
1177
+ // self.field(cx, 0).to_result()?.might_permit_raw_init(cx, zero)?
1178
+ true ,
1179
+ FieldPlacement :: Arbitrary { ref offsets, .. } => {
1180
+ let mut res = true ;
1181
+ // Check that all fields accept zero-init.
1182
+ for idx in 0 ..offsets. len ( ) {
1183
+ let field = self . field ( cx, idx) . to_result ( ) ?;
1184
+ if !field. might_permit_raw_init ( cx, zero) ? {
1185
+ res = false ;
1186
+ break ;
1187
+ }
1188
+ }
1189
+ res
1179
1190
}
1180
1191
}
1181
- // No bad field found, we are good.
1182
- true
1183
1192
}
1184
1193
}
1185
1194
}
0 commit comments