Skip to content

Commit 4d088bd

Browse files
committed
Call drop glue on the thing in a unique box
Issue #409
1 parent aad1342 commit 4d088bd

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/comp/middle/trans.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,21 @@ fn make_free_glue(bcx: @block_ctxt, v0: ValueRef, t: ty::t) {
13131313
trans_non_gc_free(bcx, v)
13141314
} else { bcx }
13151315
}
1316-
ty::ty_uniq(_) { fail "free uniq unimplemented"; }
1316+
ty::ty_uniq(content_t) {
1317+
let free_cx = new_sub_block_ctxt(bcx, "uniq_free");
1318+
let next_cx = new_sub_block_ctxt(bcx, "uniq_free_next");
1319+
let vptr = Load(bcx, v0);
1320+
let null_test = IsNull(bcx, vptr);
1321+
CondBr(bcx, null_test, next_cx.llbb, free_cx.llbb);
1322+
1323+
let bcx = free_cx;
1324+
let bcx = drop_ty(bcx, vptr, content_t);
1325+
let bcx = trans_shared_free(bcx, vptr);
1326+
Store(bcx, C_null(val_ty(vptr)), v0);
1327+
Br(bcx, next_cx.llbb);
1328+
1329+
next_cx
1330+
}
13171331
ty::ty_obj(_) {
13181332
// Call through the obj's own fields-drop glue first.
13191333
// Then free the body.
@@ -1366,10 +1380,7 @@ fn make_drop_glue(bcx: @block_ctxt, v0: ValueRef, t: ty::t) {
13661380
ty::ty_str. { tvec::make_drop_glue(bcx, v0, t) }
13671381
ty::ty_box(_) { decr_refcnt_maybe_free(bcx, v0, v0, t) }
13681382
ty::ty_uniq(_) {
1369-
let vptr = Load(bcx, v0);
1370-
let bcx = trans_shared_free(bcx, vptr);
1371-
Store(bcx, C_null(val_ty(vptr)), v0);
1372-
bcx
1383+
free_ty(bcx, v0, t)
13731384
}
13741385
ty::ty_obj(_) {
13751386
let box_cell =
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
let x = ~[0,0,0,0,0];
3+
}

0 commit comments

Comments
 (0)