diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index e71973f5299eb..1639e52fb1753 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -455,10 +455,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ptr: Pointer>, align: Align, ) -> Option { - if !M::enforce_alignment(self) || align.bytes() == 1 { - return None; - } - #[inline] fn offset_misalignment(offset: u64, align: Align) -> Option { if offset % align.bytes() == 0 { @@ -497,6 +493,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ptr: Pointer>, align: Align, ) -> InterpResult<'tcx> { + if !M::enforce_alignment(self) || align.bytes() == 1 { + return Ok(()); + } self.check_misalign(self.is_ptr_misaligned(ptr, align), CheckAlignMsg::AccessedPtr) } } diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 815a1760f4866..e51dd301ef77c 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -381,7 +381,11 @@ where meta: MemPlaceMeta, layout: TyAndLayout<'tcx>, ) -> MPlaceTy<'tcx, M::Provenance> { - let misaligned = self.is_ptr_misaligned(ptr, layout.align.abi); + let misaligned = if !M::enforce_alignment(self) || layout.align.abi.bytes() == 1 { + None + } else { + self.is_ptr_misaligned(ptr, layout.align.abi) + }; MPlaceTy { mplace: MemPlace { ptr, meta, misaligned }, layout } }