test for offset and alignment of the sized part, instead of field count

This commit is contained in:
Ralf Jung 2018-11-04 11:55:39 +01:00
parent e753d21051
commit aca76d42a0

View file

@ -374,13 +374,13 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
let (unsized_size, unsized_align) = match self.size_and_align_of(metadata, field)? {
Some(size_and_align) => size_and_align,
None => {
// A field with extern type. If this is the only field,
// we treat this struct just the same. Else, this is an error
// (for now).
if layout.fields.count() == 1 {
// A field with extern type. If this field is at offset 0 and the sized
// part makes no alignment constraints, we behave like the underlying
// extern type.
if sized_size == Size::ZERO && sized_align.abi() == 1 {
return Ok(None)
} else {
bug!("Fields cannot be extern types, unless they are the only field")
bug!("Fields cannot be extern types, unless they are at offset 0")
}
}
};