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).
This commit is contained in:
parent
dfbd4669cd
commit
e9bd650cad
2 changed files with 14 additions and 6 deletions
|
@ -451,6 +451,8 @@ impl Datum<Expr> {
|
||||||
name: &str,
|
name: &str,
|
||||||
expr_id: ast::NodeId)
|
expr_id: ast::NodeId)
|
||||||
-> DatumBlock<'a, Lvalue> {
|
-> DatumBlock<'a, Lvalue> {
|
||||||
|
debug!("to_lvalue_datum self: {}", self.to_string(bcx.ccx()));
|
||||||
|
|
||||||
assert!(ty::lltype_is_sized(bcx.tcx(), self.ty),
|
assert!(ty::lltype_is_sized(bcx.tcx(), self.ty),
|
||||||
"Trying to convert unsized value to lval");
|
"Trying to convert unsized value to lval");
|
||||||
self.match_kind(
|
self.match_kind(
|
||||||
|
|
|
@ -2061,11 +2061,17 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
|
||||||
if ty::type_is_sized(bcx.tcx(), content_ty) {
|
if ty::type_is_sized(bcx.tcx(), content_ty) {
|
||||||
deref_owned_pointer(bcx, expr, datum, content_ty)
|
deref_owned_pointer(bcx, expr, datum, content_ty)
|
||||||
} else {
|
} else {
|
||||||
// A fat pointer and an opened DST value have the same represenation
|
// A fat pointer and an opened DST value have the same
|
||||||
// just different types.
|
// represenation just different types. Since there is no
|
||||||
DatumBlock::new(bcx, Datum::new(datum.val,
|
// temporary for `*e` here (because it is unsized), we cannot
|
||||||
ty::mk_open(bcx.tcx(), content_ty),
|
// emulate the sized object code path for running drop glue and
|
||||||
datum.kind))
|
// free. Instead, we schedule cleanup for `e`, turning it into
|
||||||
|
// an lvalue.
|
||||||
|
let datum = unpack_datum!(
|
||||||
|
bcx, datum.to_lvalue_datum(bcx, "deref", expr.id));
|
||||||
|
|
||||||
|
let datum = Datum::new(datum.val, ty::mk_open(bcx.tcx(), content_ty), LvalueExpr);
|
||||||
|
DatumBlock::new(bcx, datum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2094,7 +2100,7 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
|
||||||
// just different types.
|
// just different types.
|
||||||
DatumBlock::new(bcx, Datum::new(datum.val,
|
DatumBlock::new(bcx, Datum::new(datum.val,
|
||||||
ty::mk_open(bcx.tcx(), content_ty),
|
ty::mk_open(bcx.tcx(), content_ty),
|
||||||
datum.kind))
|
LvalueExpr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue