Make constant field access account for field reordering.
This commit is contained in:
parent
8cfbffea3b
commit
1969aeb3d7
2 changed files with 5 additions and 10 deletions
|
|
@ -813,14 +813,11 @@ pub fn const_get_field<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>,
|
|||
let l = ccx.layout_of(t);
|
||||
match *l {
|
||||
layout::CEnum { .. } => bug!("element access in C-like enum const"),
|
||||
layout::Univariant { .. } | layout::Vector { .. } => const_struct_field(val, ix),
|
||||
layout::Univariant { ref variant, .. } => {
|
||||
const_struct_field(val, variant.gep_index[ix] as usize)
|
||||
}
|
||||
layout::Vector { .. } => const_struct_field(val, ix),
|
||||
layout::UntaggedUnion { .. } => const_struct_field(val, 0),
|
||||
layout::General { .. } => const_struct_field(val, ix + 1),
|
||||
layout::RawNullablePointer { .. } => {
|
||||
assert_eq!(ix, 0);
|
||||
val
|
||||
},
|
||||
layout::StructWrappedNullablePointer{ .. } => const_struct_field(val, ix),
|
||||
_ => bug!("{} does not have fields.", t)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,9 +26,7 @@ fn main() {
|
|||
assert_eq!(size_of::<E>(), 1);
|
||||
assert_eq!(size_of::<Option<E>>(), 1);
|
||||
assert_eq!(size_of::<Result<E, ()>>(), 1);
|
||||
// The next asserts are correct given the currently dumb field reordering algorithm, which actually makes this struct larger.
|
||||
assert_eq!(size_of::<S>(), 6);
|
||||
assert_eq!(size_of::<Option<S>>(), 6);
|
||||
assert_eq!(size_of::<Option<S>>(), size_of::<S>());
|
||||
let enone = None::<E>;
|
||||
let esome = Some(E::A);
|
||||
if let Some(..) = enone {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue