@@ -214,11 +214,21 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
214214 self . frame ( ) . mir
215215 }
216216
217- pub fn substs ( & self ) -> & ' tcx Substs < ' tcx > {
218- if let Some ( frame) = self . stack . last ( ) {
219- frame. instance . substs
220- } else {
221- Substs :: empty ( )
217+ pub ( super ) fn subst_and_normalize_erasing_regions < T : TypeFoldable < ' tcx > > (
218+ & self ,
219+ substs : T ,
220+ ) -> EvalResult < ' tcx , T > {
221+ match self . stack . last ( ) {
222+ Some ( frame) => Ok ( self . tcx . subst_and_normalize_erasing_regions (
223+ frame. instance . substs ,
224+ self . param_env ,
225+ & substs,
226+ ) ) ,
227+ None => if substs. needs_subst ( ) {
228+ err ! ( TooGeneric ) . into ( )
229+ } else {
230+ Ok ( substs)
231+ } ,
222232 }
223233 }
224234
@@ -228,13 +238,9 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
228238 substs : & ' tcx Substs < ' tcx >
229239 ) -> EvalResult < ' tcx , ty:: Instance < ' tcx > > {
230240 trace ! ( "resolve: {:?}, {:#?}" , def_id, substs) ;
231- trace ! ( "substs: {:#?}" , self . substs( ) ) ;
232241 trace ! ( "param_env: {:#?}" , self . param_env) ;
233- let substs = self . tcx . subst_and_normalize_erasing_regions (
234- self . substs ( ) ,
235- self . param_env ,
236- & substs,
237- ) ;
242+ let substs = self . subst_and_normalize_erasing_regions ( substs) ?;
243+ trace ! ( "substs: {:#?}" , substs) ;
238244 ty:: Instance :: resolve (
239245 * self . tcx ,
240246 self . param_env ,
@@ -274,6 +280,20 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
274280 }
275281 }
276282
283+ pub fn monomorphize_in_frame < T : TypeFoldable < ' tcx > + Subst < ' tcx > > (
284+ & self ,
285+ t : T ,
286+ ) -> EvalResult < ' tcx , T > {
287+ match self . stack . last ( ) {
288+ Some ( frame) => Ok ( self . monomorphize ( t, frame. instance . substs ) ) ,
289+ None => if t. needs_subst ( ) {
290+ err ! ( TooGeneric ) . into ( )
291+ } else {
292+ Ok ( t)
293+ } ,
294+ }
295+ }
296+
277297 pub fn monomorphize < T : TypeFoldable < ' tcx > + Subst < ' tcx > > (
278298 & self ,
279299 t : T ,
0 commit comments