Skip to content

Commit eefb3ac

Browse files
committed
interpret: better error when we ran out of memory
1 parent f9515fd commit eefb3ac

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compiler/rustc_middle/src/mir/interpret/allocation.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl AllocBytes for Box<[u8]> {
5252
}
5353

5454
fn zeroed(size: Size, _align: Align) -> Option<Self> {
55-
let bytes = Box::<[u8]>::try_new_zeroed_slice(size.bytes_usize()).ok()?;
55+
let bytes = Box::<[u8]>::try_new_zeroed_slice(size.bytes().try_into().ok()?).ok()?;
5656
// SAFETY: the box was zero-allocated, which is a valid initial value for Box<[u8]>
5757
let bytes = unsafe { bytes.assume_init() };
5858
Some(bytes)
@@ -323,7 +323,10 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
323323
/// first call this function and then call write_scalar to fill in the right data.
324324
pub fn uninit(size: Size, align: Align) -> Self {
325325
match Self::uninit_inner(size, align, || {
326-
panic!("Allocation::uninit called with panic_on_fail had allocation failure");
326+
panic!(
327+
"interpreter ran out of memory: cannot create allocation of {} bytes",
328+
size.bytes()
329+
);
327330
}) {
328331
Ok(x) => x,
329332
Err(x) => x,

0 commit comments

Comments
 (0)