@@ -214,11 +214,21 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
214
214
self . frame ( ) . mir
215
215
}
216
216
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
+ } ,
222
232
}
223
233
}
224
234
@@ -228,13 +238,9 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
228
238
substs : & ' tcx Substs < ' tcx >
229
239
) -> EvalResult < ' tcx , ty:: Instance < ' tcx > > {
230
240
trace ! ( "resolve: {:?}, {:#?}" , def_id, substs) ;
231
- trace ! ( "substs: {:#?}" , self . substs( ) ) ;
232
241
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) ;
238
244
ty:: Instance :: resolve (
239
245
* self . tcx ,
240
246
self . param_env ,
@@ -274,6 +280,20 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
274
280
}
275
281
}
276
282
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
+
277
297
pub fn monomorphize < T : TypeFoldable < ' tcx > + Subst < ' tcx > > (
278
298
& self ,
279
299
t : T ,
0 commit comments