1
+ use crate :: infer:: InferCtxt ;
1
2
use crate :: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
2
3
use crate :: middle:: lang_items:: DropInPlaceFnLangItem ;
3
4
use crate :: traits;
4
5
use crate :: ty:: print:: { FmtPrinter , Printer } ;
5
- use crate :: ty:: { self , SubstsRef , Ty , TyCtxt , TypeFoldable } ;
6
+ use crate :: ty:: { self , ParamEnv , SubstsRef , Ty , TyCtxt , TypeFoldable } ;
6
7
use rustc_hir:: def:: Namespace ;
7
8
use rustc_hir:: def_id:: DefId ;
8
9
use rustc_macros:: HashStable ;
@@ -206,17 +207,18 @@ impl<'tcx> Instance<'tcx> {
206
207
/// Presuming that coherence and type-check have succeeded, if this method is invoked
207
208
/// in a monomorphic context (i.e., like during codegen), then it is guaranteed to return
208
209
/// `Some`.
209
- pub fn resolve (
210
- tcx : TyCtxt < ' tcx > ,
210
+ pub fn resolve < ' infcx > (
211
+ infcx : & ' infcx InferCtxt < ' infcx , ' tcx > ,
211
212
param_env : ty:: ParamEnv < ' tcx > ,
212
213
def_id : DefId ,
213
214
substs : SubstsRef < ' tcx > ,
214
215
) -> Option < Instance < ' tcx > > {
216
+ let tcx = infcx. tcx ;
215
217
debug ! ( "resolve(def_id={:?}, substs={:?})" , def_id, substs) ;
216
218
let result = if let Some ( trait_def_id) = tcx. trait_of_item ( def_id) {
217
219
debug ! ( " => associated item, attempting to find impl in param_env {:#?}" , param_env) ;
218
220
let item = tcx. associated_item ( def_id) ;
219
- resolve_associated_item ( tcx , & item, param_env, trait_def_id, substs)
221
+ resolve_associated_item ( infcx , & item, param_env, trait_def_id, substs)
220
222
} else {
221
223
let ty = tcx. type_of ( def_id) ;
222
224
let item_type = tcx. subst_and_normalize_erasing_regions ( substs, param_env, & ty) ;
@@ -253,16 +255,26 @@ impl<'tcx> Instance<'tcx> {
253
255
result
254
256
}
255
257
256
- pub fn resolve_for_fn_ptr (
258
+ pub fn resolve_mono (
257
259
tcx : TyCtxt < ' tcx > ,
260
+ def_id : DefId ,
261
+ substs : SubstsRef < ' tcx > ,
262
+ ) -> Instance < ' tcx > {
263
+ tcx. infer_ctxt ( ) . enter ( |ref infcx| {
264
+ Instance :: resolve ( infcx, ParamEnv :: reveal_all ( ) , def_id, substs) . unwrap ( )
265
+ } )
266
+ }
267
+
268
+ pub fn resolve_for_fn_ptr < ' infcx > (
269
+ infcx : & ' infcx InferCtxt < ' infcx , ' tcx > ,
258
270
param_env : ty:: ParamEnv < ' tcx > ,
259
271
def_id : DefId ,
260
272
substs : SubstsRef < ' tcx > ,
261
273
) -> Option < Instance < ' tcx > > {
262
274
debug ! ( "resolve(def_id={:?}, substs={:?})" , def_id, substs) ;
263
- Instance :: resolve ( tcx , param_env, def_id, substs) . map ( |mut resolved| {
275
+ Instance :: resolve ( infcx , param_env, def_id, substs) . map ( |mut resolved| {
264
276
match resolved. def {
265
- InstanceDef :: Item ( def_id) if resolved. def . requires_caller_location ( tcx) => {
277
+ InstanceDef :: Item ( def_id) if resolved. def . requires_caller_location ( infcx . tcx ) => {
266
278
debug ! ( " => fn pointer created for function with #[track_caller]" ) ;
267
279
resolved. def = InstanceDef :: ReifyShim ( def_id) ;
268
280
}
@@ -277,13 +289,24 @@ impl<'tcx> Instance<'tcx> {
277
289
} )
278
290
}
279
291
280
- pub fn resolve_for_vtable (
292
+ pub fn resolve_for_fn_ptr_mono (
281
293
tcx : TyCtxt < ' tcx > ,
294
+ def_id : DefId ,
295
+ substs : SubstsRef < ' tcx > ,
296
+ ) -> Instance < ' tcx > {
297
+ tcx. infer_ctxt ( ) . enter ( |ref infcx| {
298
+ Instance :: resolve_for_fn_ptr ( infcx, ParamEnv :: reveal_all ( ) , def_id, substs) . unwrap ( )
299
+ } )
300
+ }
301
+
302
+ pub fn resolve_for_vtable < ' infcx > (
303
+ infcx : & ' infcx InferCtxt < ' infcx , ' tcx > ,
282
304
param_env : ty:: ParamEnv < ' tcx > ,
283
305
def_id : DefId ,
284
306
substs : SubstsRef < ' tcx > ,
285
307
) -> Option < Instance < ' tcx > > {
286
308
debug ! ( "resolve(def_id={:?}, substs={:?})" , def_id, substs) ;
309
+ let tcx = infcx. tcx ;
287
310
let fn_sig = tcx. fn_sig ( def_id) ;
288
311
let is_vtable_shim = fn_sig. inputs ( ) . skip_binder ( ) . len ( ) > 0
289
312
&& fn_sig. input ( 0 ) . skip_binder ( ) . is_param ( 0 )
@@ -292,10 +315,20 @@ impl<'tcx> Instance<'tcx> {
292
315
debug ! ( " => associated item with unsizeable self: Self" ) ;
293
316
Some ( Instance { def : InstanceDef :: VtableShim ( def_id) , substs } )
294
317
} else {
295
- Instance :: resolve ( tcx , param_env, def_id, substs)
318
+ Instance :: resolve ( infcx , param_env, def_id, substs)
296
319
}
297
320
}
298
321
322
+ pub fn resolve_for_vtable_mono (
323
+ tcx : TyCtxt < ' tcx > ,
324
+ def_id : DefId ,
325
+ substs : SubstsRef < ' tcx > ,
326
+ ) -> Instance < ' tcx > {
327
+ tcx. infer_ctxt ( ) . enter ( |ref infcx| {
328
+ Instance :: resolve_for_vtable ( infcx, ParamEnv :: reveal_all ( ) , def_id, substs) . unwrap ( )
329
+ } )
330
+ }
331
+
299
332
pub fn resolve_closure (
300
333
tcx : TyCtxt < ' tcx > ,
301
334
def_id : DefId ,
@@ -313,7 +346,7 @@ impl<'tcx> Instance<'tcx> {
313
346
pub fn resolve_drop_in_place ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> ty:: Instance < ' tcx > {
314
347
let def_id = tcx. require_lang_item ( DropInPlaceFnLangItem , None ) ;
315
348
let substs = tcx. intern_substs ( & [ ty. into ( ) ] ) ;
316
- Instance :: resolve ( tcx, ty :: ParamEnv :: reveal_all ( ) , def_id, substs) . unwrap ( )
349
+ Instance :: resolve_mono ( tcx, def_id, substs)
317
350
}
318
351
319
352
pub fn fn_once_adapter_instance (
@@ -346,13 +379,14 @@ impl<'tcx> Instance<'tcx> {
346
379
}
347
380
}
348
381
349
- fn resolve_associated_item < ' tcx > (
350
- tcx : TyCtxt < ' tcx > ,
382
+ fn resolve_associated_item < ' infcx , ' tcx > (
383
+ infcx : & ' infcx InferCtxt < ' infcx , ' tcx > ,
351
384
trait_item : & ty:: AssocItem ,
352
385
param_env : ty:: ParamEnv < ' tcx > ,
353
386
trait_id : DefId ,
354
387
rcvr_substs : SubstsRef < ' tcx > ,
355
388
) -> Option < Instance < ' tcx > > {
389
+ let tcx = infcx. tcx ;
356
390
let def_id = trait_item. def_id ;
357
391
debug ! (
358
392
"resolve_associated_item(trait_item={:?}, \
0 commit comments