Skip to content

Commit d85a9e2

Browse files
authored
Unrolled build for rust-lang#124492
Rollup merge of rust-lang#124492 - Strophox:adjust-allocbytes, r=RalfJung Generalize `adjust_from_tcx` for `Allocation` Previously, `adjust_from_tcx` would take an `Allocation` and "adjust allocation from the ones in `tcx` to a custom Machine instance [...]". This PR generalizes this so the Machine instance can also determine the `Bytes` type of the output `Allocation`. r? `@RalfJung`
2 parents 561b5de + 38181cb commit d85a9e2

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ use provenance_map::*;
2929
pub use init_mask::{InitChunk, InitChunkIter};
3030

3131
/// Functionality required for the bytes of an `Allocation`.
32-
pub trait AllocBytes:
33-
Clone + fmt::Debug + Eq + PartialEq + Hash + Deref<Target = [u8]> + DerefMut<Target = [u8]>
34-
{
32+
pub trait AllocBytes: Clone + fmt::Debug + Deref<Target = [u8]> + DerefMut<Target = [u8]> {
3533
/// Create an `AllocBytes` from a slice of `u8`.
3634
fn from_bytes<'a>(slice: impl Into<Cow<'a, [u8]>>, _align: Align) -> Self;
3735

@@ -346,10 +344,10 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
346344
}
347345
}
348346

349-
impl<Bytes: AllocBytes> Allocation<CtfeProvenance, (), Bytes> {
347+
impl Allocation {
350348
/// Adjust allocation from the ones in `tcx` to a custom Machine instance
351-
/// with a different `Provenance` and `Extra` type.
352-
pub fn adjust_from_tcx<Prov: Provenance, Extra, Err>(
349+
/// with a different `Provenance`, `Extra` and `Byte` type.
350+
pub fn adjust_from_tcx<Prov: Provenance, Extra, Bytes: AllocBytes, Err>(
353351
self,
354352
cx: &impl HasDataLayout,
355353
extra: Extra,
@@ -371,7 +369,7 @@ impl<Bytes: AllocBytes> Allocation<CtfeProvenance, (), Bytes> {
371369
}
372370
// Create allocation.
373371
Ok(Allocation {
374-
bytes,
372+
bytes: AllocBytes::from_bytes(Cow::Owned(Vec::from(bytes)), self.align),
375373
provenance: ProvenanceMap::from_presorted_ptrs(new_provenance),
376374
init_mask: self.init_mask,
377375
align: self.align,

0 commit comments

Comments
 (0)