diff options
| author | Brian Koropoff <bkoropoff@gmail.com> | 2014-10-31 23:31:16 -0700 |
|---|---|---|
| committer | Brian Koropoff <bkoropoff@gmail.com> | 2014-10-31 23:31:16 -0700 |
| commit | 8a9ced1551a8f44798989f99f32ed1657c70bfce (patch) | |
| tree | 34db03f331c099476751271b4041bc038ea76d03 | |
| parent | 5e834243b6837a2386d623e1d546a3d25057b8f5 (diff) | |
| download | rust-8a9ced1551a8f44798989f99f32ed1657c70bfce.tar.gz rust-8a9ced1551a8f44798989f99f32ed1657c70bfce.zip | |
Fix trans of index overload expressions with DST result types
Closes #18487
| -rw-r--r-- | src/librustc/middle/trans/expr.rs | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 3bfa6af4a9b..37e9a10d670 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -745,18 +745,6 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // Translate index expression. let ix_datum = unpack_datum!(bcx, trans(bcx, idx)); - // Overloaded. Evaluate `trans_overloaded_op`, which will - // invoke the user's index() method, which basically yields - // a `&T` pointer. We can then proceed down the normal - // path (below) to dereference that `&T`. - let val = - unpack_result!(bcx, - trans_overloaded_op(bcx, - index_expr, - method_call, - base_datum, - vec![(ix_datum, idx.id)], - None)); let ref_ty = ty::ty_fn_ret(monomorphize_type(bcx, method_ty)).unwrap(); let elt_ty = match ty::deref(ref_ty, true) { None => { @@ -766,7 +754,25 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } Some(elt_tm) => elt_tm.ty, }; - Datum::new(val, elt_ty, LvalueExpr) + + // Overloaded. Evaluate `trans_overloaded_op`, which will + // invoke the user's index() method, which basically yields + // a `&T` pointer. We can then proceed down the normal + // path (below) to dereference that `&T`. + let scratch = rvalue_scratch_datum(bcx, ref_ty, "overloaded_index_elt"); + unpack_result!(bcx, + trans_overloaded_op(bcx, + index_expr, + method_call, + base_datum, + vec![(ix_datum, idx.id)], + Some(SaveIn(scratch.val)))); + let datum = scratch.to_expr_datum(); + if ty::type_is_sized(bcx.tcx(), elt_ty) { + Datum::new(datum.to_llscalarish(bcx), elt_ty, LvalueExpr) + } else { + Datum::new(datum.val, ty::mk_open(bcx.tcx(), elt_ty), LvalueExpr) + } } None => { let base_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, |
