about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_mir/const_eval.rs6
-rw-r--r--src/librustc_mir/interpret/operand.rs6
2 files changed, 4 insertions, 8 deletions
diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs
index d6c0744b4e8..2b1e56e97fc 100644
--- a/src/librustc_mir/const_eval.rs
+++ b/src/librustc_mir/const_eval.rs
@@ -483,11 +483,9 @@ pub fn const_field<'tcx>(
     let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env);
     // get the operand again
     let mut op = ecx.eval_const_to_op(value, None).unwrap();
-    // adjust the alignment of `op` to the one of the allocation, since it may be a field of a
+    // Ignore the alignment when accessing the field, since it may be a field of a
     // packed struct and thus end up causing an alignment error if we read from it.
-    if let ConstValue::ByRef(_, alloc) = value.val {
-        op.force_alignment(alloc.align);
-    }
+    op.force_unaligned_access();
     // downcast
     let down = match variant {
         None => op,
diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs
index 8e026098850..04473bcb8e1 100644
--- a/src/librustc_mir/interpret/operand.rs
+++ b/src/librustc_mir/interpret/operand.rs
@@ -185,11 +185,9 @@ impl<'tcx, Tag> OpTy<'tcx, Tag> {
     /// packedness. We could clone the allocation and adjust the alignment, but that seems wasteful,
     /// since the alignment is already encoded in the allocation. We know it is alright, because
     /// validation checked everything before the initial constant entered match checking.
-    pub(crate) fn force_alignment(&mut self, align: Align) {
+    pub(crate) fn force_unaligned_access(&mut self) {
         if let Operand::Indirect(mplace) = &mut self.op {
-            if align < mplace.align {
-                mplace.align = align;
-            }
+            mplace.align = Align::from_bytes(1).unwrap();
         }
     }
 }