Skip to content

Commit 84f33fb

Browse files
committed
Cleanup trait callees
1 parent 6badef4 commit 84f33fb

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

src/librustc/middle/trans/meth.rs

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -440,39 +440,31 @@ pub fn trans_trait_callee<'a>(
440440
let _icx = push_ctxt("impl::trans_trait_callee");
441441
let mut bcx = bcx;
442442

443-
// make a local copy for trait if needed
444-
let self_ty = expr_ty_adjusted(bcx, self_expr);
445-
let self_scratch = match ty::get(self_ty).sty {
446-
ty::ty_trait(_, _, ty::RegionTraitStore(..), _, _) => {
447-
unpack_datum!(bcx, expr::trans(bcx, self_expr))
448-
}
449-
_ => {
450-
// Arrange a temporary cleanup for the object in case something
451-
// should go wrong before the method is actually *invoked*.
452-
let datum = unpack_datum!(
453-
bcx,
454-
lvalue_scratch_datum(
455-
bcx, self_ty, "__trait_callee", false, arg_cleanup_scope, (),
456-
|(), bcx, llval| expr::trans_into(bcx, self_expr,
457-
expr::SaveIn(llval))));
458-
datum.to_expr_datum()
459-
}
460-
};
443+
// Translate self_datum and take ownership of the value by
444+
// converting to an rvalue.
445+
let self_datum = unpack_datum!(
446+
bcx, expr::trans(bcx, self_expr));
447+
let self_datum = unpack_datum!(
448+
bcx, self_datum.to_rvalue_datum(bcx, "trait_callee"));
449+
450+
// Convert to by-ref since `trans_trait_callee_from_llval` wants it
451+
// that way.
452+
let self_datum = unpack_datum!(
453+
bcx, self_datum.to_ref_datum(bcx));
454+
455+
// Arrange cleanup in case something should go wrong before the
456+
// actual call occurs.
457+
let llval = self_datum.add_clean(bcx.fcx, arg_cleanup_scope);
461458

462459
let callee_ty = node_id_type(bcx, callee_id);
463-
assert!(self_scratch.kind.is_by_ref()); // FIXME why special case above??
464-
trans_trait_callee_from_llval(bcx,
465-
callee_ty,
466-
n_method,
467-
self_scratch.val)
460+
trans_trait_callee_from_llval(bcx, callee_ty, n_method, llval)
468461
}
469462

470-
pub fn trans_trait_callee_from_llval<'a>(
471-
bcx: &'a Block<'a>,
472-
callee_ty: ty::t,
473-
n_method: uint,
474-
llpair: ValueRef)
475-
-> Callee<'a> {
463+
pub fn trans_trait_callee_from_llval<'a>(bcx: &'a Block<'a>,
464+
callee_ty: ty::t,
465+
n_method: uint,
466+
llpair: ValueRef)
467+
-> Callee<'a> {
476468
/*!
477469
* Same as `trans_trait_callee()` above, except that it is given
478470
* a by-ref pointer to the object pair.
@@ -641,8 +633,8 @@ pub fn trans_trait_cast<'a>(bcx: &'a Block<'a>,
641633
/*!
642634
* Generates the code to convert from a pointer (`~T`, `&T`, etc)
643635
* into an object (`~Trait`, `&Trait`, etc). This means creating a
644-
* pair where the first word is the pointer and the second word is
645-
* an appropriate vtable.
636+
* pair where the first word is the vtable and the second word is
637+
* the pointer.
646638
*/
647639

648640
let mut bcx = bcx;

0 commit comments

Comments
 (0)