Skip to content

Commit 55def12

Browse files
committed
replace Vec<u8> with Box<[u8]>
1 parent 6ed2d87 commit 55def12

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::ty;
2828
pub struct Allocation<Tag = AllocId, Extra = ()> {
2929
/// The actual bytes of the allocation.
3030
/// Note that the bytes of a pointer represent the offset of the pointer.
31-
bytes: Vec<u8>,
31+
bytes: Box<[u8]>,
3232
/// Maps from byte addresses to extra data for each pointer.
3333
/// Only the first byte of a pointer is inserted into the map; i.e.,
3434
/// every entry in this map applies to `pointer_size` consecutive bytes starting
@@ -112,7 +112,7 @@ impl<Tag> Allocation<Tag> {
112112
align: Align,
113113
mutability: Mutability,
114114
) -> Self {
115-
let bytes = slice.into().into_owned();
115+
let bytes = Box::<[u8]>::from(slice.into());
116116
let size = Size::from_bytes(bytes.len());
117117
Self {
118118
bytes,
@@ -145,9 +145,8 @@ impl<Tag> Allocation<Tag> {
145145
});
146146
InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted)
147147
})?;
148-
// SAFETY: This turns a Box<[MaybeUninit<u8>]> into a Vec<u8>. This is safe since the box
149-
// was zero-allocated which is a valid value for u8.
150-
let bytes = unsafe { bytes.assume_init().into_vec() };
148+
// SAFETY: the box was zero-allocated, which is a valid initial value for Box<[u8]>
149+
let bytes = unsafe { bytes.assume_init() };
151150
Ok(Allocation {
152151
bytes,
153152
relocations: Relocations::new(),

0 commit comments

Comments
 (0)