@@ -199,7 +199,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
199199 kind : MemoryKind < M :: MemoryKind > ,
200200 ) -> InterpResult < ' tcx , Pointer < M :: PointerTag > > {
201201 let alloc = Allocation :: uninit ( size, align, M :: PANIC_ON_ALLOC_FAIL ) ?;
202- Ok ( self . allocate_raw_ptr ( alloc, kind) )
202+ // We can `unwrap` since `alloc` contains no pointers.
203+ Ok ( self . allocate_raw_ptr ( alloc, kind) . unwrap ( ) )
203204 }
204205
205206 pub fn allocate_bytes_ptr (
@@ -210,23 +211,25 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
210211 mutability : Mutability ,
211212 ) -> Pointer < M :: PointerTag > {
212213 let alloc = Allocation :: from_bytes ( bytes, align, mutability) ;
213- self . allocate_raw_ptr ( alloc, kind)
214+ // We can `unwrap` since `alloc` contains no pointers.
215+ self . allocate_raw_ptr ( alloc, kind) . unwrap ( )
214216 }
215217
218+ /// This can fail only of `alloc` contains relocations.
216219 pub fn allocate_raw_ptr (
217220 & mut self ,
218221 alloc : Allocation ,
219222 kind : MemoryKind < M :: MemoryKind > ,
220- ) -> Pointer < M :: PointerTag > {
223+ ) -> InterpResult < ' tcx , Pointer < M :: PointerTag > > {
221224 let id = self . tcx . reserve_alloc_id ( ) ;
222225 debug_assert_ne ! (
223226 Some ( kind) ,
224227 M :: GLOBAL_KIND . map( MemoryKind :: Machine ) ,
225228 "dynamically allocating global memory"
226229 ) ;
227- let alloc = M :: init_allocation_extra ( self , id, Cow :: Owned ( alloc) , Some ( kind) ) ;
230+ let alloc = M :: init_allocation_extra ( self , id, Cow :: Owned ( alloc) , Some ( kind) ) ? ;
228231 self . memory . alloc_map . insert ( id, ( kind, alloc. into_owned ( ) ) ) ;
229- M :: tag_alloc_base_pointer ( self , Pointer :: from ( id) )
232+ Ok ( M :: tag_alloc_base_pointer ( self , Pointer :: from ( id) ) )
230233 }
231234
232235 pub fn reallocate_ptr (
@@ -510,13 +513,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
510513 } ;
511514 M :: before_access_global ( * self . tcx , & self . machine , id, alloc, def_id, is_write) ?;
512515 // We got tcx memory. Let the machine initialize its "extra" stuff.
513- let alloc = M :: init_allocation_extra (
516+ M :: init_allocation_extra (
514517 self ,
515518 id, // always use the ID we got as input, not the "hidden" one.
516519 Cow :: Borrowed ( alloc. inner ( ) ) ,
517520 M :: GLOBAL_KIND . map ( MemoryKind :: Machine ) ,
518- ) ;
519- Ok ( alloc)
521+ )
520522 }
521523
522524 /// Gives raw access to the `Allocation`, without bounds or alignment checks.
0 commit comments