@@ -745,18 +745,6 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
745
745
// Translate index expression.
746
746
let ix_datum = unpack_datum ! ( bcx, trans( bcx, idx) ) ;
747
747
748
- // Overloaded. Evaluate `trans_overloaded_op`, which will
749
- // invoke the user's index() method, which basically yields
750
- // a `&T` pointer. We can then proceed down the normal
751
- // path (below) to dereference that `&T`.
752
- let val =
753
- unpack_result ! ( bcx,
754
- trans_overloaded_op( bcx,
755
- index_expr,
756
- method_call,
757
- base_datum,
758
- vec![ ( ix_datum, idx. id) ] ,
759
- None ) ) ;
760
748
let ref_ty = ty:: ty_fn_ret ( monomorphize_type ( bcx, method_ty) ) . unwrap ( ) ;
761
749
let elt_ty = match ty:: deref ( ref_ty, true ) {
762
750
None => {
@@ -766,7 +754,25 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
766
754
}
767
755
Some ( elt_tm) => elt_tm. ty ,
768
756
} ;
769
- Datum :: new ( val, elt_ty, LvalueExpr )
757
+
758
+ // Overloaded. Evaluate `trans_overloaded_op`, which will
759
+ // invoke the user's index() method, which basically yields
760
+ // a `&T` pointer. We can then proceed down the normal
761
+ // path (below) to dereference that `&T`.
762
+ let scratch = rvalue_scratch_datum ( bcx, ref_ty, "overloaded_index_elt" ) ;
763
+ unpack_result ! ( bcx,
764
+ trans_overloaded_op( bcx,
765
+ index_expr,
766
+ method_call,
767
+ base_datum,
768
+ vec![ ( ix_datum, idx. id) ] ,
769
+ Some ( SaveIn ( scratch. val) ) ) ) ;
770
+ let datum = scratch. to_expr_datum ( ) ;
771
+ if ty:: type_is_sized ( bcx. tcx ( ) , elt_ty) {
772
+ Datum :: new ( datum. to_llscalarish ( bcx) , elt_ty, LvalueExpr )
773
+ } else {
774
+ Datum :: new ( datum. val , ty:: mk_open ( bcx. tcx ( ) , elt_ty) , LvalueExpr )
775
+ }
770
776
}
771
777
None => {
772
778
let base_datum = unpack_datum ! ( bcx, trans_to_lvalue( bcx,
0 commit comments