Skip to content

Commit 7ae2517

Browse files
committed
Make creation of unique boxes work again
Issue #409
1 parent 865dcb6 commit 7ae2517

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/comp/middle/trans.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4246,7 +4246,9 @@ fn trans_expr_out(cx: @block_ctxt, e: @ast::expr, output: out_method) ->
42464246
CondBr(cx, cond, then_cx.llbb, else_cx.llbb);
42474247
ret rslt(join_branches(cx, [check_res, els]), C_nil());
42484248
}
4249-
ast::expr_uniq(contents) { ret trans_uniq(cx, contents); }
4249+
ast::expr_uniq(contents) {
4250+
ret trans_uniq(cx, contents, e.id);
4251+
}
42504252
ast::expr_break. { ret trans_break(e.span, cx); }
42514253
ast::expr_cont. { ret trans_cont(e.span, cx); }
42524254
ast::expr_ret(ex) { ret trans_ret(cx, ex); }
@@ -4488,7 +4490,8 @@ fn trans_put(in_cx: @block_ctxt, e: option::t<@ast::expr>) -> result {
44884490
ret rslt(next_cx, C_nil());
44894491
}
44904492

4491-
fn trans_uniq(cx: @block_ctxt, contents: @ast::expr) -> result {
4493+
fn trans_uniq(cx: @block_ctxt, contents: @ast::expr,
4494+
node_id: ast::node_id) -> result {
44924495
let bcx = cx;
44934496

44944497
let contents_ty = ty::expr_ty(bcx_tcx(bcx), contents);
@@ -4500,10 +4503,16 @@ fn trans_uniq(cx: @block_ctxt, contents: @ast::expr) -> result {
45004503

45014504
r = trans_shared_malloc(bcx, llptrty, llsz);
45024505
bcx = r.bcx;
4506+
let llptr = r.val;
4507+
4508+
let uniq_ty = node_id_type(bcx_ccx(cx), node_id);
4509+
r = alloc_ty(bcx, uniq_ty);
45034510
let llptrptr = r.val;
4511+
bcx = r.bcx;
4512+
Store(bcx, llptr, llptrptr);
45044513

4505-
let llptr = Load(bcx, llptrptr);
45064514
r = trans_expr_out(bcx, contents, save_in(llptr));
4515+
add_clean_temp(r.bcx, llptrptr, uniq_ty);
45074516
ret rslt(r.bcx, llptrptr);
45084517
}
45094518

src/test/run-pass/unique-create.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
~100;
3+
}
4+
5+
fn vec() {
6+
[0];
7+
}

src/test/run-pass/unique-init.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
let i = ~100;
3+
}

0 commit comments

Comments
 (0)