Skip to content

Commit 6fd914a

Browse files
committed
Add vtable-shim helper methods for Instance.
1 parent 0ad4c6f commit 6fd914a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/librustc/ty/instance.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,25 @@ impl<'a, 'b, 'tcx> Instance<'tcx> {
237237
result
238238
}
239239

240+
pub fn resolve_for_vtable(tcx: TyCtxt<'a, 'tcx, 'tcx>,
241+
param_env: ty::ParamEnv<'tcx>,
242+
def_id: DefId,
243+
substs: &'tcx Substs<'tcx>) -> Option<Instance<'tcx>> {
244+
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
245+
let fn_sig = tcx.fn_sig(def_id);
246+
let is_vtable_shim =
247+
fn_sig.inputs().skip_binder().len() > 0 && fn_sig.input(0).skip_binder().is_self();
248+
if is_vtable_shim {
249+
debug!(" => associated item with unsizeable self: Self");
250+
Some(Instance {
251+
def: InstanceDef::VtableShim(def_id),
252+
substs,
253+
})
254+
} else {
255+
Instance::resolve(tcx, param_env, def_id, substs)
256+
}
257+
}
258+
240259
pub fn resolve_closure(
241260
tcx: TyCtxt<'a, 'tcx, 'tcx>,
242261
def_id: DefId,
@@ -251,6 +270,14 @@ impl<'a, 'b, 'tcx> Instance<'tcx> {
251270
_ => Instance::new(def_id, substs.substs)
252271
}
253272
}
273+
274+
pub fn is_vtable_shim(&self) -> bool {
275+
if let InstanceDef::VtableShim(..) = self.def {
276+
true
277+
} else {
278+
false
279+
}
280+
}
254281
}
255282

256283
fn resolve_associated_item<'a, 'tcx>(

0 commit comments

Comments
 (0)