Skip to content

Commit 9be79fe

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 5dfb7a6 commit 9be79fe

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
@@ -2066,11 +2066,17 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
20662066
if ty::type_is_sized(bcx.tcx(), content_ty) {
20672067
deref_owned_pointer(bcx, expr, datum, content_ty)
20682068
} else {
2069-
// A fat pointer and an opened DST value have the same represenation
2070-
// just different types.
2071-
DatumBlock::new(bcx, Datum::new(datum.val,
2072-
ty::mk_open(bcx.tcx(), content_ty),
2073-
datum.kind))
2069+
// A fat pointer and an opened DST value have the same
2070+
// represenation just different types. Since there is no
2071+
// temporary for `*e` here (because it is unsized), we cannot
2072+
// emulate the sized object code path for running drop glue and
2073+
// free. Instead, we schedule cleanup for `e`, turning it into
2074+
// an lvalue.
2075+
let datum = unpack_datum!(
2076+
bcx, datum.to_lvalue_datum(bcx, "deref", expr.id));
2077+
2078+
let datum = Datum::new(datum.val, ty::mk_open(bcx.tcx(), content_ty), LvalueExpr);
2079+
DatumBlock::new(bcx, datum)
20742080
}
20752081
}
20762082

@@ -2099,7 +2105,7 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
20992105
// just different types.
21002106
DatumBlock::new(bcx, Datum::new(datum.val,
21012107
ty::mk_open(bcx.tcx(), content_ty),
2102-
datum.kind))
2108+
LvalueExpr))
21032109
}
21042110
}
21052111

0 commit comments

Comments
 (0)