Skip to content

Commit f5f67e7

Browse files
committed
Add Instance::resolve_for_fn_ptr
1 parent 012116f commit f5f67e7

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/librustc/ty/instance.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub enum InstanceDef<'tcx> {
2525
/// `<T as Trait>::method` where `method` receives unsizeable `self: Self`.
2626
VtableShim(DefId),
2727

28-
/// `fn()` where the function is annotated with `#[track_caller]`.
28+
/// `fn()` pointer where the function is annotated with `#[track_caller]`.
2929
ReifyShim(DefId),
3030

3131
/// `<fn() as FnTrait>::call_*`
@@ -297,6 +297,28 @@ impl<'tcx> Instance<'tcx> {
297297
result
298298
}
299299

300+
pub fn resolve_for_fn_ptr(
301+
tcx: TyCtxt<'tcx>,
302+
param_env: ty::ParamEnv<'tcx>,
303+
def_id: DefId,
304+
substs: SubstsRef<'tcx>,
305+
) -> Option<Instance<'tcx>> {
306+
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
307+
let fn_sig = tcx.fn_sig(def_id);
308+
// let is_reify_shim = fn_sig.inputs().skip_binder().len() > 0
309+
// && fn_sig.input(0).skip_binder().is_param(0)
310+
// && tcx.generics_of(def_id).has_self;
311+
if is_reify_shim {
312+
debug!(" => fn ptr with implicit caller location");
313+
Some(Instance {
314+
def: InstanceDef::ReifyShim(def_id),
315+
substs,
316+
})
317+
} else {
318+
Instance::resolve(tcx, param_env, def_id, substs)
319+
}
320+
}
321+
300322
pub fn resolve_for_vtable(
301323
tcx: TyCtxt<'tcx>,
302324
param_env: ty::ParamEnv<'tcx>,

0 commit comments

Comments
 (0)