Skip to content

Commit f8c69b0

Browse files
committed
refactor
1 parent dc9c303 commit f8c69b0

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

src/librustc_target/abi/mod.rs

+32-23
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ impl<'a, Ty> TyLayout<'a, Ty> {
11261126
/// left entirely uninitialized.
11271127
/// This is conservative: in doubt, it will answer `true`.
11281128
pub fn might_permit_raw_init<C, E>(
1129-
&self,
1129+
self,
11301130
cx: &C,
11311131
zero: bool,
11321132
) -> Result<bool, E>
@@ -1156,30 +1156,39 @@ impl<'a, Ty> TyLayout<'a, Ty> {
11561156
Abi::Vector { element: s, count } =>
11571157
*count == 0 || scalar_allows_raw_init(s),
11581158
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
11791190
}
11801191
}
1181-
// No bad field found, we are good.
1182-
true
11831192
}
11841193
}
11851194
}

0 commit comments

Comments
 (0)