Skip to content

Commit 90f82e1

Browse files
committed
Get borrowing working on fixed evecs.
1 parent 37b0549 commit 90f82e1

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/rustc/middle/trans/base.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -2563,6 +2563,7 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr,
25632563
}
25642564
none { trans_temp_lval(cx, e) }
25652565
};
2566+
#debug(" pre-adaptation value: %s", val_str(lv.bcx.ccx().tn, lv.val));
25662567
let lv = adapt_borrowed_value(lv, arg, e);
25672568
let mut bcx = lv.bcx;
25682569
let mut val = lv.val;
@@ -2618,7 +2619,7 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr,
26182619
}
26192620

26202621
if !is_bot && arg.ty != e_ty || ty::type_has_params(arg.ty) {
2621-
#debug(" casting from %s", val_str(bcx.ccx().tn, val));
2622+
#debug(" casting from %s", val_str(bcx.ccx().tn, val));
26222623
val = PointerCast(bcx, val, lldestty);
26232624
}
26242625
#debug("--- trans_arg_expr passing %s", val_str(bcx.ccx().tn, val));
@@ -2652,10 +2653,21 @@ fn adapt_borrowed_value(lv: lval_result, _arg: ty::arg,
26522653
ty::ty_estr(_) |
26532654
ty::ty_evec(_, _) {
26542655
let ccx = bcx.ccx();
2656+
let val = alt lv.kind {
2657+
temporary { lv.val }
2658+
owned { load_if_immediate(bcx, lv.val, e_ty) }
2659+
owned_imm { lv.val }
2660+
};
2661+
26552662
let unit_ty = ty::sequence_element_type(ccx.tcx, e_ty);
26562663
let llunit_ty = type_of(ccx, unit_ty);
2657-
let (base, len) = tvec::get_base_and_len(bcx, lv.val, e_ty);
2664+
let (base, len) = tvec::get_base_and_len(bcx, val, e_ty);
26582665
let p = alloca(bcx, T_struct([T_ptr(llunit_ty), ccx.int_type]));
2666+
2667+
#debug("adapt_borrowed_value: adapting %s to %s",
2668+
val_str(bcx.ccx().tn, val),
2669+
val_str(bcx.ccx().tn, p));
2670+
26592671
Store(bcx, base, GEPi(bcx, p, [0, abi::slice_elt_base]));
26602672
Store(bcx, len, GEPi(bcx, p, [0, abi::slice_elt_len]));
26612673
ret lval_temp(bcx, p);
@@ -3064,12 +3076,7 @@ fn trans_expr_save_in(bcx: block, e: @ast::expr, dest: ValueRef)
30643076
fn trans_temp_lval(bcx: block, e: @ast::expr) -> lval_result {
30653077
let _icx = bcx.insn_ctxt("trans_temp_lval");
30663078
let mut bcx = bcx;
3067-
if expr_is_lval(bcx, e) && !expr_is_borrowed(bcx, e) {
3068-
// if the expression is borrowed, then are not actually passing the
3069-
// lvalue itself, but rather an adaptation of it. This is a bit of a
3070-
// hack, though, but it only needs to exist so long as we have
3071-
// reference modes and the like---otherwise, all potentially borrowed
3072-
// things will go directly through trans_expr() as they ought to.
3079+
if expr_is_lval(bcx, e) {
30733080
ret trans_lval(bcx, e);
30743081
} else {
30753082
let ty = expr_ty(bcx, e);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// xfail-test
2+
fn foo(x: [int]/&) -> int {
3+
x[0]
4+
}
5+
6+
fn main() {
7+
let p = [1,2,3,4,5]/_;
8+
assert foo(p) == 1;
9+
}

0 commit comments

Comments
 (0)