@@ -216,11 +216,21 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
216216 self . frame ( ) . mir
217217 }
218218
219- pub fn substs ( & self ) -> & ' tcx Substs < ' tcx > {
220- if let Some ( frame) = self . stack . last ( ) {
221- frame. instance . substs
222- } else {
223- Substs :: empty ( )
219+ pub ( super ) fn subst_and_normalize_erasing_regions < T : TypeFoldable < ' tcx > > (
220+ & self ,
221+ substs : T ,
222+ ) -> EvalResult < ' tcx , T > {
223+ match self . stack . last ( ) {
224+ Some ( frame) => Ok ( self . tcx . subst_and_normalize_erasing_regions (
225+ frame. instance . substs ,
226+ self . param_env ,
227+ & substs,
228+ ) ) ,
229+ None => if substs. needs_subst ( ) {
230+ err ! ( TooGeneric ) . into ( )
231+ } else {
232+ Ok ( substs)
233+ } ,
224234 }
225235 }
226236
@@ -230,13 +240,9 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
230240 substs : & ' tcx Substs < ' tcx >
231241 ) -> EvalResult < ' tcx , ty:: Instance < ' tcx > > {
232242 trace ! ( "resolve: {:?}, {:#?}" , def_id, substs) ;
233- trace ! ( "substs: {:#?}" , self . substs( ) ) ;
234243 trace ! ( "param_env: {:#?}" , self . param_env) ;
235- let substs = self . tcx . subst_and_normalize_erasing_regions (
236- self . substs ( ) ,
237- self . param_env ,
238- & substs,
239- ) ;
244+ let substs = self . subst_and_normalize_erasing_regions ( substs) ?;
245+ trace ! ( "substs: {:#?}" , substs) ;
240246 ty:: Instance :: resolve (
241247 * self . tcx ,
242248 self . param_env ,
@@ -276,6 +282,20 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
276282 }
277283 }
278284
285+ pub fn monomorphize_in_frame < T : TypeFoldable < ' tcx > + Subst < ' tcx > > (
286+ & self ,
287+ t : T ,
288+ ) -> EvalResult < ' tcx , T > {
289+ match self . stack . last ( ) {
290+ Some ( frame) => Ok ( self . monomorphize ( t, frame. instance . substs ) ) ,
291+ None => if t. needs_subst ( ) {
292+ err ! ( TooGeneric ) . into ( )
293+ } else {
294+ Ok ( t)
295+ } ,
296+ }
297+ }
298+
279299 pub fn monomorphize < T : TypeFoldable < ' tcx > + Subst < ' tcx > > (
280300 & self ,
281301 t : T ,
0 commit comments