/// The point where linking happens. Resolve a (def_id, substs)
/// pair to an instance.
- pub fn resolve(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Option<Instance<'tcx>> {
+ pub fn resolve(tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Option<Instance<'tcx>> {
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) {
debug!(" => associated item, attempting to find impl");
let item = tcx.associated_item(def_id);
- resolve_associated_item(tcx, &item, trait_def_id, substs)
+ resolve_associated_item(tcx, &item, param_env, trait_def_id, substs)
} else {
let ty = tcx.type_of(def_id);
let item_type = tcx.trans_apply_param_substs(substs, &ty);
fn resolve_associated_item<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_item: &ty::AssociatedItem,
+ param_env: ty::ParamEnv<'tcx>,
trait_id: DefId,
rcvr_substs: &'tcx Substs<'tcx>
) -> Option<Instance<'tcx>> {
def_id, trait_id, rcvr_substs);
let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs);
- let vtbl = tcx.trans_fulfill_obligation(DUMMY_SP, ty::Binder(trait_ref));
+ let vtbl = tcx.trans_fulfill_obligation(DUMMY_SP, param_env, ty::Binder(trait_ref));
// Now that we know which impl is being used, we can dispatch to
// the actual function:
let mut callsites = VecDeque::new();
// Only do inlining into fn bodies.
- if let MirSource::Fn(_) = self.source {
+ if let MirSource::Fn(caller_id) = self.source {
for (bb, bb_data) in caller_mir.basic_blocks().iter_enumerated() {
// Don't inline calls that are in cleanup blocks.
if bb_data.is_cleanup { continue; }
if let TerminatorKind::Call {
func: Operand::Constant(ref f), .. } = terminator.kind {
if let ty::TyFnDef(callee_def_id, substs) = f.ty.sty {
- if let Some(instance) = Instance::resolve(self.tcx, callee_def_id, substs) {
+ let caller_def_id = self.tcx.hir.local_def_id(caller_id);
+ let param_env = self.tcx.param_env(caller_def_id);
+
+ if let Some(instance) = Instance::resolve(self.tcx, param_env, callee_def_id, substs) {
callsites.push_back(CallSite {
callee: instance.def_id(),
substs: instance.substs,