Skip to content

Commit 8a9ced1

Browse files
committed
Fix trans of index overload expressions with DST result types
Closes #18487
1 parent 5e83424 commit 8a9ced1

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/librustc/middle/trans/expr.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -745,18 +745,6 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
745745
// Translate index expression.
746746
let ix_datum = unpack_datum!(bcx, trans(bcx, idx));
747747

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));
760748
let ref_ty = ty::ty_fn_ret(monomorphize_type(bcx, method_ty)).unwrap();
761749
let elt_ty = match ty::deref(ref_ty, true) {
762750
None => {
@@ -766,7 +754,25 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
766754
}
767755
Some(elt_tm) => elt_tm.ty,
768756
};
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+
}
770776
}
771777
None => {
772778
let base_datum = unpack_datum!(bcx, trans_to_lvalue(bcx,

0 commit comments

Comments
 (0)