Skip to content

Commit e9bd650

Browse files
committed
Schedule cleanup for &* on fat owned pointers
For example `let _x: &Trait = &*(box Foo as Box<Trait>);`. There was a bug where no cleanup would be scheduled by the deref. No test because cleanup-auto-borrow-obj.rs is a test for this once we remove trait cross-borrowing (done on another branch).
1 parent dfbd466 commit e9bd650

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/librustc/middle/trans/datum.rs

+2
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ impl Datum<Expr> {
451451
name: &str,
452452
expr_id: ast::NodeId)
453453
-> DatumBlock<'a, Lvalue> {
454+
debug!("to_lvalue_datum self: {}", self.to_string(bcx.ccx()));
455+
454456
assert!(ty::lltype_is_sized(bcx.tcx(), self.ty),
455457
"Trying to convert unsized value to lval");
456458
self.match_kind(

src/librustc/middle/trans/expr.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -2061,11 +2061,17 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
20612061
if ty::type_is_sized(bcx.tcx(), content_ty) {
20622062
deref_owned_pointer(bcx, expr, datum, content_ty)
20632063
} else {
2064-
// A fat pointer and an opened DST value have the same represenation
2065-
// just different types.
2066-
DatumBlock::new(bcx, Datum::new(datum.val,
2067-
ty::mk_open(bcx.tcx(), content_ty),
2068-
datum.kind))
2064+
// A fat pointer and an opened DST value have the same
2065+
// represenation just different types. Since there is no
2066+
// temporary for `*e` here (because it is unsized), we cannot
2067+
// emulate the sized object code path for running drop glue and
2068+
// free. Instead, we schedule cleanup for `e`, turning it into
2069+
// an lvalue.
2070+
let datum = unpack_datum!(
2071+
bcx, datum.to_lvalue_datum(bcx, "deref", expr.id));
2072+
2073+
let datum = Datum::new(datum.val, ty::mk_open(bcx.tcx(), content_ty), LvalueExpr);
2074+
DatumBlock::new(bcx, datum)
20692075
}
20702076
}
20712077

@@ -2094,7 +2100,7 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
20942100
// just different types.
20952101
DatumBlock::new(bcx, Datum::new(datum.val,
20962102
ty::mk_open(bcx.tcx(), content_ty),
2097-
datum.kind))
2103+
LvalueExpr))
20982104
}
20992105
}
21002106

0 commit comments

Comments
 (0)