Skip to content

Commit 8659de0

Browse files
committed
rustc_trans: use an Lvalue Datum for an unsized lvalue to avoid bogus drops.
1 parent 3b0cafb commit 8659de0

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/librustc_trans/trans/common.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,7 @@ pub fn type_needs_unwind_cleanup<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<
214214
}
215215

216216
pub fn type_needs_drop<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
217-
// Unsized types cannot be dropped automatically - these are lvalues pointing
218-
// to alloca's containing the actual data pointer (and the unsizing info),
219-
// which only be obtained by dereferencing a pointer from which moves are
220-
// not allowed. Datum & friends could possibly be adjusted to avoid getting
221-
// this far - maybe the (*data, info) aggregate could be an SSA value?
222-
// Lvalues don't have to be pointers, just behave like a pointer, but there
223-
// is no telling what other implicit assumptions are lurking around.
224-
ty::type_contents(cx, ty).needs_drop(cx) && type_is_sized(cx, ty)
217+
ty::type_contents(cx, ty).needs_drop(cx)
225218
}
226219

227220
fn type_is_newtype_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {

src/librustc_trans/trans/expr.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,13 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
463463
let ptr_ty = type_of::in_memory_type_of(bcx.ccx(), unsized_ty).ptr_to();
464464
let base = PointerCast(bcx, lval.val, ptr_ty);
465465

466-
let scratch = rvalue_scratch_datum(bcx, unsized_ty, "__fat_ptr");
467-
Store(bcx, base, get_dataptr(bcx, scratch.val));
468-
Store(bcx, info, get_len(bcx, scratch.val));
466+
let llty = type_of::type_of(bcx.ccx(), unsized_ty);
467+
// HACK(eddyb) get around issues with lifetime intrinsics.
468+
let scratch = alloca_no_lifetime(bcx, llty, "__fat_ptr");
469+
Store(bcx, base, get_dataptr(bcx, scratch));
470+
Store(bcx, info, get_len(bcx, scratch));
469471

470-
DatumBlock::new(bcx, scratch.to_expr_datum())
472+
DatumBlock::new(bcx, Datum::new(scratch, unsized_ty, LvalueExpr))
471473
}
472474

473475
fn unsize_unique_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,

0 commit comments

Comments
 (0)