Skip to content

Commit 7ccd71f

Browse files
U-NOV2010\eugalsU-NOV2010\eugals
U-NOV2010\eugals
authored and
U-NOV2010\eugals
committed
will not copy trait_callee on stack if it's source expr is a plain borrowed ref
1 parent f96edfd commit 7ccd71f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/librustc/middle/trans/expr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ pub fn trans_to_datum(bcx: @mut Block, expr: @ast::Expr) -> DatumBlock {
343343
_ => {}
344344
}
345345

346-
347346
let scratch = scratch_datum(bcx, target_obj_ty,
348347
"__auto_borrow_obj", false);
349348

src/librustc/middle/trans/meth.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,22 @@ pub fn trans_trait_callee(bcx: @mut Block,
434434
let _icx = push_ctxt("impl::trans_trait_callee");
435435
let mut bcx = bcx;
436436

437+
// make a local copy for trait if needed
437438
let self_ty = expr_ty_adjusted(bcx, self_expr);
438-
let self_scratch = scratch_datum(bcx, self_ty, "__trait_callee", false);
439-
bcx = expr::trans_into(bcx, self_expr, expr::SaveIn(self_scratch.val));
439+
let self_scratch = match ty::get(self_ty).sty {
440+
ty::ty_trait(_, _, ty::RegionTraitStore(*), _, _) => {
441+
unpack_datum!(bcx, expr::trans_to_datum(bcx, self_expr))
442+
}
443+
_ => {
444+
let d = scratch_datum(bcx, self_ty, "__trait_callee", false);
445+
bcx = expr::trans_into(bcx, self_expr, expr::SaveIn(d.val));
446+
// Arrange a temporary cleanup for the object in case something
447+
// should go wrong before the method is actually *invoked*.
448+
d.add_clean(bcx);
449+
d
450+
}
451+
};
440452

441-
// Arrange a temporary cleanup for the object in case something
442-
// should go wrong before the method is actually *invoked*.
443-
self_scratch.add_clean(bcx);
444453

445454
let callee_ty = node_id_type(bcx, callee_id);
446455
trans_trait_callee_from_llval(bcx,

0 commit comments

Comments
 (0)