-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Compute the layout of uninhabited structs #64987
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ use rustc::mir; | |
use rustc::mir::interpret::truncate; | ||
use rustc::ty::{self, Ty}; | ||
use rustc::ty::layout::{ | ||
self, Size, Abi, Align, LayoutOf, TyLayout, HasDataLayout, VariantIdx, PrimitiveExt | ||
self, Size, Align, LayoutOf, TyLayout, HasDataLayout, VariantIdx, PrimitiveExt | ||
}; | ||
use rustc::ty::TypeFoldable; | ||
|
||
|
@@ -377,20 +377,17 @@ where | |
layout::FieldPlacement::Array { stride, .. } => { | ||
let len = base.len(self)?; | ||
if field >= len { | ||
// This can be violated because this runs during promotion on code where the | ||
// type system has not yet ensured that such things don't happen. | ||
// This can be violated because the index (field) can be a runtime value | ||
// provided by the user. | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
debug!("tried to access element {} of array/slice with length {}", field, len); | ||
throw_panic!(BoundsCheck { len, index: field }); | ||
} | ||
stride * field | ||
} | ||
layout::FieldPlacement::Union(count) => { | ||
// FIXME(#64506) `UninhabitedValue` can be removed when this issue is resolved | ||
if base.layout.abi == Abi::Uninhabited { | ||
throw_unsup!(UninhabitedValue); | ||
} | ||
assert!(field < count as u64, | ||
"Tried to access field {} of union with {} fields", field, count); | ||
"Tried to access field {} of union {:#?} with {} fields", | ||
field, base.layout, count); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add this assert to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// Offset is always 0 | ||
Size::from_bytes(0) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// check-pass | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#[derive(Copy, Clone)] | ||
pub struct ChildStdin { | ||
inner: AnonPipe, | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
enum AnonPipe {} | ||
|
||
const FOO: () = { | ||
union Foo { | ||
a: ChildStdin, | ||
b: (), | ||
} | ||
let x = unsafe { Foo { b: () }.a }; | ||
let x = &x.inner; | ||
}; | ||
|
||
fn main() {} |
Uh oh!
There was an error while loading. Please reload this page.