Skip to content

Commit 8a5800e

Browse files
committed
take ParamEnv into account when resolving
1 parent 24fc50f commit 8a5800e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/librustc/ty/instance.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ impl<'a, 'b, 'tcx> Instance<'tcx> {
118118

119119
/// The point where linking happens. Resolve a (def_id, substs)
120120
/// pair to an instance.
121-
pub fn resolve(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Option<Instance<'tcx>> {
121+
pub fn resolve(tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Option<Instance<'tcx>> {
122122
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
123123
let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) {
124124
debug!(" => associated item, attempting to find impl");
125125
let item = tcx.associated_item(def_id);
126-
resolve_associated_item(tcx, &item, trait_def_id, substs)
126+
resolve_associated_item(tcx, &item, param_env, trait_def_id, substs)
127127
} else {
128128
let ty = tcx.type_of(def_id);
129129
let item_type = tcx.trans_apply_param_substs(substs, &ty);
@@ -184,6 +184,7 @@ fn resolve_closure<'a, 'tcx>(
184184
fn resolve_associated_item<'a, 'tcx>(
185185
tcx: TyCtxt<'a, 'tcx, 'tcx>,
186186
trait_item: &ty::AssociatedItem,
187+
param_env: ty::ParamEnv<'tcx>,
187188
trait_id: DefId,
188189
rcvr_substs: &'tcx Substs<'tcx>
189190
) -> Option<Instance<'tcx>> {
@@ -194,7 +195,7 @@ fn resolve_associated_item<'a, 'tcx>(
194195
def_id, trait_id, rcvr_substs);
195196

196197
let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs);
197-
let vtbl = tcx.trans_fulfill_obligation(DUMMY_SP, ty::Binder(trait_ref));
198+
let vtbl = tcx.trans_fulfill_obligation(DUMMY_SP, param_env, ty::Binder(trait_ref));
198199

199200
// Now that we know which impl is being used, we can dispatch to
200201
// the actual function:

src/librustc_mir/transform/inline.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
7878
let mut callsites = VecDeque::new();
7979

8080
// Only do inlining into fn bodies.
81-
if let MirSource::Fn(_) = self.source {
81+
if let MirSource::Fn(caller_id) = self.source {
8282
for (bb, bb_data) in caller_mir.basic_blocks().iter_enumerated() {
8383
// Don't inline calls that are in cleanup blocks.
8484
if bb_data.is_cleanup { continue; }
@@ -88,7 +88,10 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
8888
if let TerminatorKind::Call {
8989
func: Operand::Constant(ref f), .. } = terminator.kind {
9090
if let ty::TyFnDef(callee_def_id, substs) = f.ty.sty {
91-
if let Some(instance) = Instance::resolve(self.tcx, callee_def_id, substs) {
91+
let caller_def_id = self.tcx.hir.local_def_id(caller_id);
92+
let param_env = self.tcx.param_env(caller_def_id);
93+
94+
if let Some(instance) = Instance::resolve(self.tcx, param_env, callee_def_id, substs) {
9295
callsites.push_back(CallSite {
9396
callee: instance.def_id(),
9497
substs: instance.substs,

0 commit comments

Comments
 (0)