]> git.lizzy.rs Git - rust.git/commitdiff
Prepare miri for unsized locals
authorOliver Schneider <github35764891676564198441@oli-obk.de>
Fri, 31 Aug 2018 11:46:51 +0000 (13:46 +0200)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Thu, 25 Oct 2018 14:47:35 +0000 (16:47 +0200)
src/librustc_mir/interpret/place.rs

index a4bb15662d8b272996e1ce69e50116967d9d6a57..b7bc4867307fb2b0aafe1eed27eed631da3c786a 100644 (file)
@@ -880,9 +880,16 @@ pub fn allocate(
         layout: TyLayout<'tcx>,
         kind: MemoryKind<M::MemoryKinds>,
     ) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
-        assert!(!layout.is_unsized(), "cannot alloc memory for unsized type");
-        let ptr = self.memory.allocate(layout.size, layout.align, kind)?;
-        Ok(MPlaceTy::from_aligned_ptr(ptr, layout))
+        if layout.is_unsized() {
+            assert!(self.tcx.features().unsized_locals, "cannot alloc memory for unsized type");
+            // allocate a fat pointer slot instead
+            let fat = self.tcx.mk_mut_ptr(layout.ty);
+            let fat = self.layout_of(fat)?;
+            self.allocate(fat, kind)
+        } else {
+            let ptr = self.memory.allocate(layout.size, layout.align, kind)?;
+            Ok(MPlaceTy::from_aligned_ptr(ptr, layout))
+        }
     }
 
     pub fn write_discriminant_index(