diff options
| author | Rune Tynan <runetynan@gmail.com> | 2023-02-13 23:16:56 -0500 |
|---|---|---|
| committer | Rune Tynan <runetynan@gmail.com> | 2023-02-20 13:47:11 -0500 |
| commit | b2455dc91ce7d43ea883ea5d2ec8adb6e90fc4d4 (patch) | |
| tree | 09d4a6e921706e9a5c08bfcc828a7d7ad90ae001 /compiler | |
| parent | 6f407d67b8ae387f763fa8e8dbc269b16a996ce3 (diff) | |
| download | rust-b2455dc91ce7d43ea883ea5d2ec8adb6e90fc4d4.tar.gz rust-b2455dc91ce7d43ea883ea5d2ec8adb6e90fc4d4.zip | |
Add mentioned from_raw_bytes constructor
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/allocation.rs | 17 |
1 files changed, 17 insertions, 0 deletions
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 @@ impl AllocRange { // The constructors are all without extra; the extra gets added by a machine hook later. impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> { + /// 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<Cow<'a, [u8]>>, |
