@@ -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
329329impl < ' 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