@@ -7,6 +7,7 @@ use std::collections::hash_map::Entry;
77use std:: hash:: Hash ;
88
99use rustc_data_structures:: fx:: FxHashMap ;
10+ use std:: fmt;
1011
1112use rustc_ast:: Mutability ;
1213use rustc_hir:: def_id:: DefId ;
@@ -179,6 +180,28 @@ impl<K: Hash + Eq, V> interpret::AllocMap<K, V> for FxHashMap<K, V> {
179180crate type CompileTimeEvalContext < ' mir , ' tcx > =
180181 InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ;
181182
183+ #[ derive( Debug , PartialEq , Eq , Copy , Clone ) ]
184+ pub enum MemoryKind {
185+ Heap ,
186+ }
187+
188+ impl fmt:: Display for MemoryKind {
189+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
190+ match self {
191+ MemoryKind :: Heap => write ! ( f, "heap allocation" ) ,
192+ }
193+ }
194+ }
195+
196+ impl interpret:: MayLeak for MemoryKind {
197+ #[ inline( always) ]
198+ fn may_leak ( self ) -> bool {
199+ match self {
200+ MemoryKind :: Heap => false ,
201+ }
202+ }
203+ }
204+
182205impl interpret:: MayLeak for ! {
183206 #[ inline( always) ]
184207 fn may_leak ( self ) -> bool {
@@ -222,6 +245,8 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
222245impl < ' mir , ' tcx > interpret:: Machine < ' mir , ' tcx > for CompileTimeInterpreter < ' mir , ' tcx > {
223246 compile_time_machine ! ( <' mir, ' tcx>) ;
224247
248+ type MemoryKind = MemoryKind ;
249+
225250 type MemoryExtra = MemoryExtra ;
226251
227252 fn find_mir_or_eval_fn (
@@ -317,7 +342,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
317342 let ptr = ecx. memory . allocate (
318343 Size :: from_bytes ( size as u64 ) ,
319344 align,
320- interpret:: MemoryKind :: ConstHeap ,
345+ interpret:: MemoryKind :: Machine ( MemoryKind :: Heap ) ,
321346 ) ;
322347 ecx. write_scalar ( Scalar :: Ptr ( ptr) , dest) ?;
323348 }
0 commit comments