about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2015-02-24 08:22:43 +0200
committerEduard Burtescu <edy.burt@gmail.com>2015-02-24 08:40:15 +0200
commit8659de0334208ccb6b3a4929109275857da84e81 (patch)
tree3abe74c8c2c78b75b4f94826f7182bf7329a57c6
parent3b0cafbcd7c2fe092888b58ad5994bd280eb40b9 (diff)
downloadrust-8659de0334208ccb6b3a4929109275857da84e81.tar.gz
rust-8659de0334208ccb6b3a4929109275857da84e81.zip
rustc_trans: use an Lvalue Datum for an unsized lvalue to avoid bogus drops.
-rw-r--r--src/librustc_trans/trans/common.rs9
-rw-r--r--src/librustc_trans/trans/expr.rs10
2 files changed, 7 insertions, 12 deletions
diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs
index 0689b0ded6e..a3ba506fc46 100644
--- a/src/librustc_trans/trans/common.rs
+++ b/src/librustc_trans/trans/common.rs
@@ -214,14 +214,7 @@ pub fn type_needs_unwind_cleanup<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<
 }
 
 pub fn type_needs_drop<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
-    // Unsized types cannot be dropped automatically - these are lvalues pointing
-    // to alloca's containing the actual data pointer (and the unsizing info),
-    // which only be obtained by dereferencing a pointer from which moves are
-    // not allowed. Datum & friends could possibly be adjusted to avoid getting
-    // this far - maybe the (*data, info) aggregate could be an SSA value?
-    // Lvalues don't have to be pointers, just behave like a pointer, but there
-    // is no telling what other implicit assumptions are lurking around.
-    ty::type_contents(cx, ty).needs_drop(cx) && type_is_sized(cx, ty)
+    ty::type_contents(cx, ty).needs_drop(cx)
 }
 
 fn type_is_newtype_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs
index ca15da94f07..9e9ee453752 100644
--- a/src/librustc_trans/trans/expr.rs
+++ b/src/librustc_trans/trans/expr.rs
@@ -463,11 +463,13 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
         let ptr_ty = type_of::in_memory_type_of(bcx.ccx(), unsized_ty).ptr_to();
         let base = PointerCast(bcx, lval.val, ptr_ty);
 
-        let scratch = rvalue_scratch_datum(bcx, unsized_ty, "__fat_ptr");
-        Store(bcx, base, get_dataptr(bcx, scratch.val));
-        Store(bcx, info, get_len(bcx, scratch.val));
+        let llty = type_of::type_of(bcx.ccx(), unsized_ty);
+        // HACK(eddyb) get around issues with lifetime intrinsics.
+        let scratch = alloca_no_lifetime(bcx, llty, "__fat_ptr");
+        Store(bcx, base, get_dataptr(bcx, scratch));
+        Store(bcx, info, get_len(bcx, scratch));
 
-        DatumBlock::new(bcx, scratch.to_expr_datum())
+        DatumBlock::new(bcx, Datum::new(scratch, unsized_ty, LvalueExpr))
     }
 
     fn unsize_unique_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,