@@ -42,11 +42,10 @@ pub trait AllocBytes:
42
42
43
43
/// Create a zeroed `AllocBytes` of the specified size and alignment;
44
44
/// call the callback error handler if there is an error in allocating the memory.
45
- fn zeroed < ' tcx , F : Fn ( ) -> InterpError < ' tcx > > (
45
+ fn zeroed (
46
46
size : Size ,
47
47
_align : Align ,
48
- handle_alloc_fail : F ,
49
- ) -> Result < Self , InterpError < ' tcx > > ;
48
+ ) -> Option < Self > ;
50
49
}
51
50
52
51
// Default `bytes` for `Allocation` is a `Box<[u8]>`.
@@ -59,16 +58,14 @@ impl AllocBytes for Box<[u8]> {
59
58
Box :: < [ u8 ] > :: from ( slice. into ( ) )
60
59
}
61
60
62
- fn zeroed < ' tcx , F : Fn ( ) -> InterpError < ' tcx > > (
61
+ fn zeroed (
63
62
size : Size ,
64
63
_align : Align ,
65
- handle_alloc_fail : F ,
66
- ) -> Result < Self , InterpError < ' tcx > > {
67
- let bytes = Box :: < [ u8 ] > :: try_new_zeroed_slice ( size. bytes_usize ( ) )
68
- . map_err ( |_| handle_alloc_fail ( ) ) ?;
64
+ ) -> Option < Self > {
65
+ let bytes = Box :: < [ u8 ] > :: try_new_zeroed_slice ( size. bytes_usize ( ) ) . ok ( ) ?;
69
66
// SAFETY: the box was zero-allocated, which is a valid initial value for Box<[u8]>
70
67
let bytes = unsafe { bytes. assume_init ( ) } ;
71
- Ok ( bytes)
68
+ Some ( bytes)
72
69
}
73
70
}
74
71
@@ -304,7 +301,7 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
304
301
///
305
302
/// If `panic_on_fail` is true, this will never return `Err`.
306
303
pub fn uninit < ' tcx > ( size : Size , align : Align , panic_on_fail : bool ) -> InterpResult < ' tcx , Self > {
307
- let handle_alloc_fail = || -> InterpError < ' tcx > {
304
+ let bytes = Bytes :: zeroed ( size , align ) . ok_or_else ( || {
308
305
// This results in an error that can happen non-deterministically, since the memory
309
306
// available to the compiler can change between runs. Normally queries are always
310
307
// deterministic. However, we can be non-deterministic here because all uses of const
@@ -317,9 +314,7 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
317
314
tcx. sess . delay_span_bug ( DUMMY_SP , "exhausted memory during interpretation" )
318
315
} ) ;
319
316
InterpError :: ResourceExhaustion ( ResourceExhaustionInfo :: MemoryExhausted )
320
- } ;
321
-
322
- let bytes = Bytes :: zeroed ( size, align, handle_alloc_fail) ?;
317
+ } ) ?;
323
318
324
319
Ok ( Allocation {
325
320
bytes,
0 commit comments