Skip to content

Commit f976291

Browse files
committed
Correctly subst the fn_sig so that we get the correct types
Otherwise we get random TySelfs there, which means operations on RETURN_PLACE end up breaking down badly.
1 parent ef4f486 commit f976291

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/librustc_mir/shim.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ fn build_clone_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
294294
{
295295
debug!("build_clone_shim(def_id={:?})", def_id);
296296

297-
let mut builder = CloneShimBuilder::new(tcx, def_id);
297+
let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty);
298298
let is_copy = !self_ty.moves_by_default(tcx, tcx.param_env(def_id), builder.span);
299299

300300
match self_ty.sty {
@@ -327,8 +327,14 @@ struct CloneShimBuilder<'a, 'tcx: 'a> {
327327
}
328328

329329
impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
330-
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Self {
331-
let sig = tcx.fn_sig(def_id);
330+
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
331+
def_id: DefId,
332+
self_ty: Ty<'tcx>) -> Self {
333+
// we must subst the self_ty because it's
334+
// otherwise going to be TySelf and we can't index
335+
// or access fields of a Place of type TySelf.
336+
let substs = tcx.mk_substs_trait(self_ty, &[]);
337+
let sig = tcx.fn_sig(def_id).subst(tcx, substs);
332338
let sig = tcx.erase_late_bound_regions(&sig);
333339
let span = tcx.def_span(def_id);
334340

0 commit comments

Comments
 (0)