Skip to content

Commit b2455dc

Browse files
committed
Add mentioned from_raw_bytes constructor
1 parent 6f407d6 commit b2455dc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,23 @@ impl AllocRange {
270270

271271
// The constructors are all without extra; the extra gets added by a machine hook later.
272272
impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
273+
/// Creates an allocation from an existing `Bytes` value - this is needed for miri FFI support
274+
pub fn from_raw_bytes<'a>(
275+
bytes: Bytes,
276+
align: Align,
277+
mutability: Mutability,
278+
) -> Self {
279+
let size = Size::from_bytes(bytes.len());
280+
Self {
281+
bytes,
282+
provenance: ProvenanceMap::new(),
283+
init_mask: InitMask::new(size, true),
284+
align,
285+
mutability,
286+
extra: (),
287+
}
288+
}
289+
273290
/// Creates an allocation initialized by the given bytes
274291
pub fn from_bytes<'a>(
275292
slice: impl Into<Cow<'a, [u8]>>,

0 commit comments

Comments
 (0)