Skip to content

Commit 5573ad7

Browse files
committed
rustc: Fix an LLVM assertion that tripped when borrowing a by-val method receiver.
In certain lvalue code paths, the type of the borrowed value was not being used to generate temporary spills. I'm a bit surprised we didn't hit this sooner.
1 parent e767011 commit 5573ad7

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/rustc/middle/trans/base.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3112,24 +3112,24 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr,
31123112

31133113
ast::by_copy | ast::by_move => {
31143114
// Ensure that an owned copy of the value is in memory:
3115-
let alloc = alloc_ty(bcx, arg.ty);
3115+
let alloc = alloc_ty(bcx, e_ty);
31163116
let move_out = arg_mode == ast::by_move ||
31173117
ccx.maps.last_use_map.contains_key(e.id);
31183118
if lv.kind == lv_temporary { revoke_clean(bcx, val); }
3119-
if lv.kind == lv_owned || !ty::type_is_immediate(arg.ty) {
3120-
memmove_ty(bcx, alloc, val, arg.ty);
3121-
if move_out && ty::type_needs_drop(ccx.tcx, arg.ty) {
3122-
bcx = zero_mem(bcx, val, arg.ty);
3119+
if lv.kind == lv_owned || !ty::type_is_immediate(e_ty) {
3120+
memmove_ty(bcx, alloc, val, e_ty);
3121+
if move_out && ty::type_needs_drop(ccx.tcx, e_ty) {
3122+
bcx = zero_mem(bcx, val, e_ty);
31233123
}
31243124
} else { Store(bcx, val, alloc); }
31253125
val = alloc;
31263126
if lv.kind != lv_temporary && !move_out {
3127-
bcx = take_ty(bcx, val, arg.ty);
3127+
bcx = take_ty(bcx, val, e_ty);
31283128
}
31293129

31303130
// In the event that failure occurs before the call actually
31313131
// happens, have to cleanup this copy:
3132-
add_clean_temp_mem(bcx, val, arg.ty);
3132+
add_clean_temp_mem(bcx, val, e_ty);
31333133
vec::push(temp_cleanups, val);
31343134
}
31353135
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait Foo {
2+
fn foo(self);
3+
}
4+
5+
impl &[int]: Foo {
6+
fn foo(self) {}
7+
}
8+
9+
fn main() {
10+
let items = ~[ 3, 5, 1, 2, 4 ];
11+
items.foo();
12+
}
13+

0 commit comments

Comments
 (0)