提交 8659de03 编写于 作者: E Eduard Burtescu

rustc_trans: use an Lvalue Datum for an unsized lvalue to avoid bogus drops.

上级 3b0cafbc
......@@ -214,14 +214,7 @@ fn type_needs_unwind_cleanup_<'tcx>(tcx: &ty::ctxt<'tcx>,
}
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 {
......
......@@ -463,11 +463,13 @@ fn unsize_expr<'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>,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册