about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_trans/adt.rs11
-rw-r--r--src/test/run-pass/nonzero-enum.rs4
2 files changed, 5 insertions, 10 deletions
diff --git a/src/librustc_trans/adt.rs b/src/librustc_trans/adt.rs
index 0690bea6c2f..c7a177196ff 100644
--- a/src/librustc_trans/adt.rs
+++ b/src/librustc_trans/adt.rs
@@ -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)
     }
 }
diff --git a/src/test/run-pass/nonzero-enum.rs b/src/test/run-pass/nonzero-enum.rs
index 2cd3136b0eb..fc92c9df9f7 100644
--- a/src/test/run-pass/nonzero-enum.rs
+++ b/src/test/run-pass/nonzero-enum.rs
@@ -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 {