@@ -24,8 +24,8 @@ use rustc_middle::ty::{self, layout::TyAndLayout, Ty};
24
24
use rustc_ast:: Mutability ;
25
25
26
26
use super :: {
27
- AllocId , Allocation , ConstAllocation , InterpCx , MPlaceTy , Machine , MemoryKind , PlaceTy ,
28
- Projectable , ValueVisitor ,
27
+ AllocId , Allocation , InterpCx , MPlaceTy , Machine , MemoryKind , PlaceTy , Projectable ,
28
+ ValueVisitor ,
29
29
} ;
30
30
use crate :: const_eval;
31
31
use crate :: errors:: { DanglingPtrInFinal , UnsupportedUntypedPointer } ;
@@ -455,19 +455,23 @@ impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>>
455
455
{
456
456
/// A helper function that allocates memory for the layout given and gives you access to mutate
457
457
/// 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 .
459
459
pub fn intern_with_temp_alloc (
460
460
& mut self ,
461
461
layout : TyAndLayout < ' tcx > ,
462
462
f : impl FnOnce (
463
463
& mut InterpCx < ' mir , ' tcx , M > ,
464
464
& PlaceTy < ' tcx , M :: Provenance > ,
465
465
) -> 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.
467
468
let dest = self . allocate ( layout, MemoryKind :: Stack ) ?;
468
469
f ( self , & dest. clone ( ) . into ( ) ) ?;
469
470
let mut alloc = self . memory . alloc_map . remove ( & dest. ptr ( ) . provenance . unwrap ( ) ) . unwrap ( ) . 1 ;
470
471
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)
472
476
}
473
477
}
0 commit comments