diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index 0d21ef7f327..23d6d321947 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -459,10 +459,9 @@ pub fn intern_const_alloc_for_constprop< M: CompileTimeMachine<'mir, 'tcx, T>, >( ecx: &mut InterpCx<'mir, 'tcx, M>, - ret: &MPlaceTy<'tcx>, + alloc_id: AllocId, ) -> InterpResult<'tcx, ()> { // Move allocation to `tcx`. - let alloc_id = ret.ptr().provenance.unwrap(); let Some((_, mut alloc)) = ecx.memory.alloc_map.remove(&alloc_id) else { // Pointer not found in local memory map. It is either a pointer to the global // map, or dangling. diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index c575da611c7..58844aed783 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -61,7 +61,6 @@ use rustc_hir::def::DefKind; use rustc_index::bit_set::BitSet; use rustc_index::IndexVec; use rustc_macros::newtype_index; -use rustc_middle::mir::interpret::GlobalAlloc; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::layout::LayoutOf; @@ -861,14 +860,10 @@ fn op_to_prop_const<'tcx>( return None; } - intern_const_alloc_for_constprop(ecx, &mplace).ok()?; let pointer = mplace.ptr().into_pointer_or_addr().ok()?; let (alloc_id, offset) = pointer.into_parts(); - match ecx.tcx.global_alloc(alloc_id) { - GlobalAlloc::Memory(_) => return Some(ConstValue::Indirect { alloc_id, offset }), - // Fallthrough to copying the data. - _ => {} - } + intern_const_alloc_for_constprop(ecx, alloc_id).ok()?; + return Some(ConstValue::Indirect { alloc_id, offset }); } // Everything failed: create a new allocation to hold the data.