Skip to content

Commit 73e2b46

Browse files
committed
Prepare miri for unsized locals
1 parent 0f97048 commit 73e2b46

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/librustc_mir/interpret/place.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,9 +880,16 @@ where
880880
layout: TyLayout<'tcx>,
881881
kind: MemoryKind<M::MemoryKinds>,
882882
) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
883-
assert!(!layout.is_unsized(), "cannot alloc memory for unsized type");
884-
let ptr = self.memory.allocate(layout.size, layout.align, kind)?;
885-
Ok(MPlaceTy::from_aligned_ptr(ptr, layout))
883+
if layout.is_unsized() {
884+
assert!(self.tcx.features().unsized_locals, "cannot alloc memory for unsized type");
885+
// allocate a fat pointer slot instead
886+
let fat = self.tcx.mk_mut_ptr(layout.ty);
887+
let fat = self.layout_of(fat)?;
888+
self.allocate(fat, kind)
889+
} else {
890+
let ptr = self.memory.allocate(layout.size, layout.align, kind)?;
891+
Ok(MPlaceTy::from_aligned_ptr(ptr, layout))
892+
}
886893
}
887894

888895
pub fn write_discriminant_index(

0 commit comments

Comments
 (0)