@@ -24,8 +24,8 @@ use rustc_middle::ty::{self, layout::TyAndLayout, Ty};
2424use rustc_ast:: Mutability ;
2525
2626use super :: {
27- AllocId , Allocation , ConstAllocation , InterpCx , MPlaceTy , Machine , MemoryKind , PlaceTy ,
28- Projectable , ValueVisitor ,
27+ AllocId , Allocation , InterpCx , MPlaceTy , Machine , MemoryKind , PlaceTy , Projectable ,
28+ ValueVisitor ,
2929} ;
3030use crate :: const_eval;
3131use crate :: errors:: { DanglingPtrInFinal , UnsupportedUntypedPointer } ;
@@ -455,19 +455,23 @@ impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>>
455455{
456456 /// A helper function that allocates memory for the layout given and gives you access to mutate
457457 /// it. Once your own mutation code is done, the backing `Allocation` is removed from the
458- /// current `Memory` and returned .
458+ /// current `Memory` and interned as read-only into the global memory .
459459 pub fn intern_with_temp_alloc (
460460 & mut self ,
461461 layout : TyAndLayout < ' tcx > ,
462462 f : impl FnOnce (
463463 & mut InterpCx < ' mir , ' tcx , M > ,
464464 & PlaceTy < ' tcx , M :: Provenance > ,
465465 ) -> InterpResult < ' tcx , ( ) > ,
466- ) -> InterpResult < ' tcx , ConstAllocation < ' tcx > > {
466+ ) -> InterpResult < ' tcx , AllocId > {
467+ // `allocate` picks a fresh AllocId that we will associate with its data below.
467468 let dest = self . allocate ( layout, MemoryKind :: Stack ) ?;
468469 f ( self , & dest. clone ( ) . into ( ) ) ?;
469470 let mut alloc = self . memory . alloc_map . remove ( & dest. ptr ( ) . provenance . unwrap ( ) ) . unwrap ( ) . 1 ;
470471 alloc. mutability = Mutability :: Not ;
471- Ok ( self . tcx . mk_const_alloc ( alloc) )
472+ let alloc = self . tcx . mk_const_alloc ( alloc) ;
473+ let alloc_id = dest. ptr ( ) . provenance . unwrap ( ) ; // this was just allocated, it must have provenance
474+ self . tcx . set_alloc_id_memory ( alloc_id, alloc) ;
475+ Ok ( alloc_id)
472476 }
473477}
0 commit comments