From b2455dc91ce7d43ea883ea5d2ec8adb6e90fc4d4 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Mon, 13 Feb 2023 23:16:56 -0500 Subject: [PATCH] Add mentioned from_raw_bytes constructor --- .../src/mir/interpret/allocation.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 2ddfdbbc25a..974db3f4402 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -270,6 +270,23 @@ pub fn subrange(self, subrange: AllocRange) -> AllocRange { // The constructors are all without extra; the extra gets added by a machine hook later. impl Allocation { + /// Creates an allocation from an existing `Bytes` value - this is needed for miri FFI support + pub fn from_raw_bytes<'a>( + bytes: Bytes, + align: Align, + mutability: Mutability, + ) -> Self { + let size = Size::from_bytes(bytes.len()); + Self { + bytes, + provenance: ProvenanceMap::new(), + init_mask: InitMask::new(size, true), + align, + mutability, + extra: (), + } + } + /// Creates an allocation initialized by the given bytes pub fn from_bytes<'a>( slice: impl Into>,