Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miri: accept extern types in structs if they are the only field #55672

Merged
merged 6 commits into from
Nov 19, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test for offset and alignment of the sized part, instead of field count
  • Loading branch information
RalfJung committed Nov 4, 2018
commit aca76d42a05c419a539d9b34fa30b88d4cdcadcc
10 changes: 5 additions & 5 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
};
Expand Down