Skip to content

Commit aca76d4

Browse files
committed
test for offset and alignment of the sized part, instead of field count
1 parent e753d21 commit aca76d4

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/librustc_mir/interpret/eval_context.rs

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

0 commit comments

Comments
 (0)