diff options
| author | Ralf Jung <post@ralfj.de> | 2024-06-17 12:04:52 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-06-17 12:04:52 +0200 |
| commit | eefb3ac8afcdcc6fd6723991e127eb4f70ab3f62 (patch) | |
| tree | 2f2b3b1b9d943d2f5404ca572ee3f076da544d17 | |
| parent | f9515fdd5aa132e27d9b580a35b27f4b453251c1 (diff) | |
interpret: better error when we ran out of memory
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/allocation.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index b0f8a047b82..2fc466c0e7e 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -52,7 +52,7 @@ impl AllocBytes for Box<[u8]> { } fn zeroed(size: Size, _align: Align) -> Option<Self> { - let bytes = Box::<[u8]>::try_new_zeroed_slice(size.bytes_usize()).ok()?; + let bytes = Box::<[u8]>::try_new_zeroed_slice(size.bytes().try_into().ok()?).ok()?; // SAFETY: the box was zero-allocated, which is a valid initial value for Box<[u8]> let bytes = unsafe { bytes.assume_init() }; Some(bytes) @@ -323,7 +323,10 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> { /// first call this function and then call write_scalar to fill in the right data. pub fn uninit(size: Size, align: Align) -> Self { match Self::uninit_inner(size, align, || { - panic!("Allocation::uninit called with panic_on_fail had allocation failure"); + panic!( + "interpreter ran out of memory: cannot create allocation of {} bytes", + size.bytes() + ); }) { Ok(x) => x, Err(x) => x, |
