@@ -61,12 +61,24 @@ impl<'tcx> Instance<'tcx> {
6161 )
6262 }
6363
64- fn fn_sig_noadjust ( & self , tcx : TyCtxt < ' tcx > ) -> PolyFnSig < ' tcx > {
64+ pub fn fn_sig ( & self , tcx : TyCtxt < ' tcx > ) -> PolyFnSig < ' tcx > {
6565 let ty = self . ty ( tcx) ;
6666 match ty. kind {
6767 ty:: FnDef ( ..) |
6868 // Shims currently have type FnPtr. Not sure this should remain.
69- ty:: FnPtr ( _) => ty. fn_sig ( tcx) ,
69+ ty:: FnPtr ( _) => {
70+ let mut sig = ty. fn_sig ( tcx) ;
71+ if let InstanceDef :: VtableShim ( ..) = self . def {
72+ // Modify fn(self, ...) to fn(self: *mut Self, ...)
73+ sig = sig. map_bound ( |mut sig| {
74+ let mut inputs_and_output = sig. inputs_and_output . to_vec ( ) ;
75+ inputs_and_output[ 0 ] = tcx. mk_mut_ptr ( inputs_and_output[ 0 ] ) ;
76+ sig. inputs_and_output = tcx. intern_type_list ( & inputs_and_output) ;
77+ sig
78+ } ) ;
79+ }
80+ sig
81+ }
7082 ty:: Closure ( def_id, substs) => {
7183 let sig = substs. as_closure ( ) . sig ( def_id, tcx) ;
7284
@@ -107,22 +119,8 @@ impl<'tcx> Instance<'tcx> {
107119 )
108120 } )
109121 }
110- _ => bug ! ( "unexpected type {:?} in Instance::fn_sig_noadjust" , ty)
111- }
112- }
113-
114- pub fn fn_sig ( & self , tcx : TyCtxt < ' tcx > ) -> ty:: PolyFnSig < ' tcx > {
115- let mut fn_sig = self . fn_sig_noadjust ( tcx) ;
116- if let InstanceDef :: VtableShim ( ..) = self . def {
117- // Modify fn(self, ...) to fn(self: *mut Self, ...)
118- fn_sig = fn_sig. map_bound ( |mut fn_sig| {
119- let mut inputs_and_output = fn_sig. inputs_and_output . to_vec ( ) ;
120- inputs_and_output[ 0 ] = tcx. mk_mut_ptr ( inputs_and_output[ 0 ] ) ;
121- fn_sig. inputs_and_output = tcx. intern_type_list ( & inputs_and_output) ;
122- fn_sig
123- } ) ;
122+ _ => bug ! ( "unexpected type {:?} in Instance::fn_sig" , ty)
124123 }
125- fn_sig
126124 }
127125}
128126
0 commit comments