From 55def120a4d54123625ad05c4d6384c5044642f1 Mon Sep 17 00:00:00 2001 From: The8472 Date: Thu, 5 Aug 2021 19:52:08 +0200 Subject: [PATCH] replace Vec with Box<[u8]> --- compiler/rustc_middle/src/mir/interpret/allocation.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index ada6e097766..5964efa78e9 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -28,7 +28,7 @@ use crate::ty; pub struct Allocation { /// The actual bytes of the allocation. /// Note that the bytes of a pointer represent the offset of the pointer. - bytes: Vec, + bytes: Box<[u8]>, /// Maps from byte addresses to extra data for each pointer. /// Only the first byte of a pointer is inserted into the map; i.e., /// every entry in this map applies to `pointer_size` consecutive bytes starting @@ -112,7 +112,7 @@ impl Allocation { align: Align, mutability: Mutability, ) -> Self { - let bytes = slice.into().into_owned(); + let bytes = Box::<[u8]>::from(slice.into()); let size = Size::from_bytes(bytes.len()); Self { bytes, @@ -145,9 +145,8 @@ impl Allocation { }); InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted) })?; - // SAFETY: This turns a Box<[MaybeUninit]> into a Vec. This is safe since the box - // was zero-allocated which is a valid value for u8. - let bytes = unsafe { bytes.assume_init().into_vec() }; + // SAFETY: the box was zero-allocated, which is a valid initial value for Box<[u8]> + let bytes = unsafe { bytes.assume_init() }; Ok(Allocation { bytes, relocations: Relocations::new(),