@@ -133,8 +133,8 @@ pub fn trans_self_arg(bcx: block,
133133 let _icx = push_ctxt ( "impl::trans_self_arg" ) ;
134134 let mut temp_cleanups = ~[ ] ;
135135
136- // Compute the type of self.
137- let self_ty = monomorphize_type ( bcx, mentry . self_ty ) ;
136+ // self is passed as an opaque box in the environment slot
137+ let self_ty = ty :: mk_opaque_box ( bcx. tcx ( ) ) ;
138138 let result = trans_arg_expr ( bcx,
139139 self_ty,
140140 mentry. self_mode ,
@@ -576,7 +576,6 @@ pub fn trans_trait_callee_from_llval(bcx: block,
576576 let llbox = Load ( bcx, GEPi ( bcx, llpair, [ 0 u, abi:: trt_field_box] ) ) ;
577577
578578 // Munge `llself` appropriately for the type of `self` in the method.
579- let self_mode;
580579 match explicit_self {
581580 ast:: sty_static => {
582581 bcx. tcx ( ) . sess . bug ( "shouldn't see static method here" ) ;
@@ -597,12 +596,6 @@ pub fn trans_trait_callee_from_llval(bcx: block,
597596 llself = llbox;
598597 }
599598 }
600-
601- let llscratch = alloca ( bcx, val_ty ( llself) ) ;
602- Store ( bcx, llself, llscratch) ;
603- llself = llscratch;
604-
605- self_mode = ty:: ByRef ;
606599 }
607600 ast:: sty_box( _) => {
608601 // Bump the reference count on the box.
@@ -615,28 +608,20 @@ pub fn trans_trait_callee_from_llval(bcx: block,
615608 ty:: BoxTraitStore => llself = llbox,
616609 _ => bcx. tcx ( ) . sess . bug ( "@self receiver with non-@Trait" )
617610 }
618-
619- let llscratch = alloca ( bcx, val_ty ( llself) ) ;
620- Store ( bcx, llself, llscratch) ;
621- llself = llscratch;
622-
623- self_mode = ty:: ByRef ;
624611 }
625612 ast:: sty_uniq( _) => {
626613 // Pass the unique pointer.
627614 match store {
628615 ty:: UniqTraitStore => llself = llbox,
629616 _ => bcx. tcx ( ) . sess . bug ( "~self receiver with non-~Trait" )
630617 }
631-
632- let llscratch = alloca ( bcx, val_ty ( llself) ) ;
633- Store ( bcx, llself, llscratch) ;
634- llself = llscratch;
635-
636- self_mode = ty:: ByRef ;
637618 }
638619 }
639620
621+ let llscratch = alloca ( bcx, val_ty ( llself) ) ;
622+ Store ( bcx, llself, llscratch) ;
623+ llself = PointerCast ( bcx, llscratch, Type :: opaque_box ( ccx) . ptr_to ( ) ) ;
624+
640625 // Load the function from the vtable and cast it to the expected type.
641626 debug ! ( "(translating trait callee) loading method" ) ;
642627 let llcallee_ty = type_of_fn_from_ty ( ccx, callee_ty) ;
@@ -652,7 +637,7 @@ pub fn trans_trait_callee_from_llval(bcx: block,
652637 llfn : mptr,
653638 llself : llself,
654639 self_ty : ty:: mk_opaque_box ( bcx. tcx ( ) ) ,
655- self_mode : self_mode ,
640+ self_mode : ty :: ByRef ,
656641 explicit_self : explicit_self
657642 /* XXX: Some(llbox) */
658643 } )
0 commit comments