1+ use crate :: infer:: InferCtxt ;
12use crate :: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
23use crate :: middle:: lang_items:: DropInPlaceFnLangItem ;
34use crate :: traits;
45use crate :: ty:: print:: { FmtPrinter , Printer } ;
5- use crate :: ty:: { self , SubstsRef , Ty , TyCtxt , TypeFoldable } ;
6+ use crate :: ty:: { self , ParamEnv , SubstsRef , Ty , TyCtxt , TypeFoldable } ;
67use rustc_hir:: def:: Namespace ;
78use rustc_hir:: def_id:: DefId ;
89use rustc_macros:: HashStable ;
@@ -206,17 +207,18 @@ impl<'tcx> Instance<'tcx> {
206207 /// Presuming that coherence and type-check have succeeded, if this method is invoked
207208 /// in a monomorphic context (i.e., like during codegen), then it is guaranteed to return
208209 /// `Some`.
209- pub fn resolve (
210- tcx : TyCtxt < ' tcx > ,
210+ pub fn resolve < ' infcx > (
211+ infcx : & ' infcx InferCtxt < ' infcx , ' tcx > ,
211212 param_env : ty:: ParamEnv < ' tcx > ,
212213 def_id : DefId ,
213214 substs : SubstsRef < ' tcx > ,
214215 ) -> Option < Instance < ' tcx > > {
216+ let tcx = infcx. tcx ;
215217 debug ! ( "resolve(def_id={:?}, substs={:?})" , def_id, substs) ;
216218 let result = if let Some ( trait_def_id) = tcx. trait_of_item ( def_id) {
217219 debug ! ( " => associated item, attempting to find impl in param_env {:#?}" , param_env) ;
218220 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)
220222 } else {
221223 let ty = tcx. type_of ( def_id) ;
222224 let item_type = tcx. subst_and_normalize_erasing_regions ( substs, param_env, & ty) ;
@@ -253,16 +255,26 @@ impl<'tcx> Instance<'tcx> {
253255 result
254256 }
255257
256- pub fn resolve_for_fn_ptr (
258+ pub fn resolve_mono (
257259 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 > ,
258270 param_env : ty:: ParamEnv < ' tcx > ,
259271 def_id : DefId ,
260272 substs : SubstsRef < ' tcx > ,
261273 ) -> Option < Instance < ' tcx > > {
262274 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| {
264276 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 ) => {
266278 debug ! ( " => fn pointer created for function with #[track_caller]" ) ;
267279 resolved. def = InstanceDef :: ReifyShim ( def_id) ;
268280 }
@@ -277,13 +289,24 @@ impl<'tcx> Instance<'tcx> {
277289 } )
278290 }
279291
280- pub fn resolve_for_vtable (
292+ pub fn resolve_for_fn_ptr_mono (
281293 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 > ,
282304 param_env : ty:: ParamEnv < ' tcx > ,
283305 def_id : DefId ,
284306 substs : SubstsRef < ' tcx > ,
285307 ) -> Option < Instance < ' tcx > > {
286308 debug ! ( "resolve(def_id={:?}, substs={:?})" , def_id, substs) ;
309+ let tcx = infcx. tcx ;
287310 let fn_sig = tcx. fn_sig ( def_id) ;
288311 let is_vtable_shim = fn_sig. inputs ( ) . skip_binder ( ) . len ( ) > 0
289312 && fn_sig. input ( 0 ) . skip_binder ( ) . is_param ( 0 )
@@ -292,10 +315,20 @@ impl<'tcx> Instance<'tcx> {
292315 debug ! ( " => associated item with unsizeable self: Self" ) ;
293316 Some ( Instance { def : InstanceDef :: VtableShim ( def_id) , substs } )
294317 } else {
295- Instance :: resolve ( tcx , param_env, def_id, substs)
318+ Instance :: resolve ( infcx , param_env, def_id, substs)
296319 }
297320 }
298321
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+
299332 pub fn resolve_closure (
300333 tcx : TyCtxt < ' tcx > ,
301334 def_id : DefId ,
@@ -313,7 +346,7 @@ impl<'tcx> Instance<'tcx> {
313346 pub fn resolve_drop_in_place ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> ty:: Instance < ' tcx > {
314347 let def_id = tcx. require_lang_item ( DropInPlaceFnLangItem , None ) ;
315348 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)
317350 }
318351
319352 pub fn fn_once_adapter_instance (
@@ -346,13 +379,14 @@ impl<'tcx> Instance<'tcx> {
346379 }
347380}
348381
349- fn resolve_associated_item < ' tcx > (
350- tcx : TyCtxt < ' tcx > ,
382+ fn resolve_associated_item < ' infcx , ' tcx > (
383+ infcx : & ' infcx InferCtxt < ' infcx , ' tcx > ,
351384 trait_item : & ty:: AssocItem ,
352385 param_env : ty:: ParamEnv < ' tcx > ,
353386 trait_id : DefId ,
354387 rcvr_substs : SubstsRef < ' tcx > ,
355388) -> Option < Instance < ' tcx > > {
389+ let tcx = infcx. tcx ;
356390 let def_id = trait_item. def_id ;
357391 debug ! (
358392 "resolve_associated_item(trait_item={:?}, \
0 commit comments