@@ -762,60 +762,33 @@ pub fn trans_arg_expr(bcx: @mut Block,
762
762
val = arg_datum. to_ref_llval ( bcx) ;
763
763
}
764
764
DontAutorefArg => {
765
- match self_mode {
765
+ let need_scratch = ty:: type_needs_drop ( bcx. tcx ( ) , arg_datum. ty ) ||
766
+ ( bcx. expr_is_lval ( arg_expr) &&
767
+ arg_datum. appropriate_mode ( bcx. tcx ( ) ) . is_by_ref ( ) ) ;
768
+
769
+ let arg_datum = if need_scratch {
770
+ let scratch = scratch_datum ( bcx, arg_datum. ty , "__self" , false ) ;
771
+ arg_datum. store_to_datum ( bcx, INIT , scratch) ;
772
+
773
+ // Technically, ownership of val passes to the callee.
774
+ // However, we must cleanup should we fail before the
775
+ // callee is actually invoked.
776
+ scratch. add_clean ( bcx) ;
777
+ temp_cleanups. push ( scratch. val ) ;
778
+
779
+ scratch
780
+ } else {
781
+ arg_datum
782
+ } ;
783
+
784
+ val = match self_mode {
766
785
ty:: ByRef => {
767
- // This assertion should really be valid, but because
768
- // the explicit self code currently passes by-ref, it
769
- // does not hold.
770
- //
771
- //assert !bcx.ccx().maps.moves_map.contains_key(
772
- // &arg_expr.id);
773
- debug ! ( "by ref arg with type %s, storing to scratch" ,
774
- bcx. ty_to_str( arg_datum. ty) ) ;
775
- let scratch = scratch_datum ( bcx, arg_datum. ty ,
776
- "__self" , false ) ;
777
-
778
- arg_datum. store_to_datum ( bcx,
779
- INIT ,
780
- scratch) ;
781
-
782
- // Technically, ownership of val passes to the callee.
783
- // However, we must cleanup should we fail before the
784
- // callee is actually invoked.
785
- scratch. add_clean ( bcx) ;
786
- temp_cleanups. push ( scratch. val ) ;
787
-
788
- val = scratch. to_ref_llval ( bcx) ;
786
+ debug ! ( "by ref arg with type %s" , bcx. ty_to_str( arg_datum. ty) ) ;
787
+ arg_datum. to_ref_llval ( bcx)
789
788
}
790
789
ty:: ByCopy => {
791
- if ty:: type_needs_drop ( bcx. tcx ( ) , arg_datum. ty ) ||
792
- arg_datum. appropriate_mode ( bcx. tcx ( ) ) . is_by_ref ( ) {
793
- debug ! ( "by copy arg with type %s, storing to scratch" ,
794
- bcx. ty_to_str( arg_datum. ty) ) ;
795
- let scratch = scratch_datum ( bcx, arg_datum. ty ,
796
- "__arg" , false ) ;
797
-
798
- arg_datum. store_to_datum ( bcx,
799
- INIT ,
800
- scratch) ;
801
-
802
- // Technically, ownership of val passes to the callee.
803
- // However, we must cleanup should we fail before the
804
- // callee is actually invoked.
805
- scratch. add_clean ( bcx) ;
806
- temp_cleanups. push ( scratch. val ) ;
807
-
808
- match scratch. appropriate_mode ( bcx. tcx ( ) ) {
809
- ByValue => val = Load ( bcx, scratch. val ) ,
810
- ByRef ( _) => val = scratch. val ,
811
- }
812
- } else {
813
- debug ! ( "by copy arg with type %s" , bcx. ty_to_str( arg_datum. ty) ) ;
814
- match arg_datum. mode {
815
- ByRef ( _) => val = Load ( bcx, arg_datum. val ) ,
816
- ByValue => val = arg_datum. val ,
817
- }
818
- }
790
+ debug ! ( "by copy arg with type %s" , bcx. ty_to_str( arg_datum. ty) ) ;
791
+ arg_datum. to_appropriate_llval ( bcx)
819
792
}
820
793
}
821
794
}
0 commit comments