mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
parent
5d5136df9f
commit
268a9fe5fb
@ -2030,11 +2030,11 @@ fn copy_val_no_check(cx: @block_ctxt, action: copy_action, dst: ValueRef,
|
||||
ret take_ty(bcx, dst, t);
|
||||
}
|
||||
if ty::type_is_unique_box(ccx.tcx, t) {
|
||||
//let bcx = cx;
|
||||
let bcx = cx;
|
||||
// FIXME (409): Write a test and uncomment
|
||||
//if action == DROP_EXISTING { bcx = drop_ty(cx, dst, t); }
|
||||
//ret trans_uniq::copy_val(bcx, dst, src, t);
|
||||
fail;
|
||||
check trans_uniq::type_is_unique_box(bcx, t);
|
||||
ret trans_uniq::copy_val(bcx, dst, src, t);
|
||||
}
|
||||
if type_is_structural_or_param(ccx.tcx, t) || ty::type_is_vec(ccx.tcx, t)
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ import trans::{
|
||||
new_sub_block_ctxt
|
||||
};
|
||||
|
||||
export trans_uniq, make_free_glue, type_is_unique_box;
|
||||
export trans_uniq, make_free_glue, type_is_unique_box, copy_val;
|
||||
|
||||
pure fn type_is_unique_box(bcx: @block_ctxt, ty: ty::t) -> bool {
|
||||
unchecked {
|
||||
@ -35,6 +35,8 @@ fn trans_uniq(cx: @block_ctxt, contents: @ast::expr,
|
||||
let content_ty = content_ty(bcx, uniq_ty);
|
||||
let {bcx, val: llptr} = alloc_uniq(bcx, uniq_ty);
|
||||
|
||||
add_clean_temp(bcx, llptr, uniq_ty);
|
||||
|
||||
bcx = move_val_if_temp(bcx, INIT, llptr, lv,
|
||||
content_ty);
|
||||
|
||||
@ -56,8 +58,6 @@ fn alloc_uniq(cx: @block_ctxt, uniq_ty: ty::t)
|
||||
bcx = r.bcx;
|
||||
let llptr = r.val;
|
||||
|
||||
add_clean_temp(bcx, llptr, uniq_ty);
|
||||
|
||||
ret rslt(bcx, llptr);
|
||||
}
|
||||
|
||||
@ -86,4 +86,18 @@ fn content_ty(bcx: @block_ctxt, t: ty::t)
|
||||
alt ty::struct(bcx_tcx(bcx), t) {
|
||||
ty::ty_uniq({ty: ct, _}) { ct }
|
||||
}
|
||||
}
|
||||
|
||||
fn copy_val(cx: @block_ctxt, dst: ValueRef, src: ValueRef,
|
||||
ty: ty::t) : type_is_unique_box(cx, ty) -> @block_ctxt {
|
||||
|
||||
let content_ty = content_ty(cx, ty);
|
||||
let {bcx, val: llptr} = alloc_uniq(cx, ty);
|
||||
Store(bcx, llptr, dst);
|
||||
|
||||
let src = Load(bcx, src);
|
||||
let dst = Load(bcx, dst);
|
||||
let bcx = trans::copy_val(bcx, INIT, dst, src, content_ty);
|
||||
Store(bcx, src, llptr);
|
||||
ret bcx;
|
||||
}
|
9
src/test/run-pass/unique-decl-init-copy.rs
Normal file
9
src/test/run-pass/unique-decl-init-copy.rs
Normal file
@ -0,0 +1,9 @@
|
||||
fn main() {
|
||||
let i = ~mutable 1;
|
||||
// Should be a copy
|
||||
let j = i;
|
||||
*i = 2;
|
||||
*j = 3;
|
||||
assert *i == 2;
|
||||
assert *j == 3;
|
||||
}
|
5
src/test/run-pass/unique-decl-init.rs
Normal file
5
src/test/run-pass/unique-decl-init.rs
Normal file
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
let i = ~1;
|
||||
let j = i;
|
||||
assert *j == 1;
|
||||
}
|
Loading…
Reference in New Issue
Block a user