]> git.lizzy.rs Git - rust.git/commitdiff
take ParamEnv into account when resolving
authorDouglas Campos <qmx@qmx.me>
Thu, 28 Sep 2017 02:22:55 +0000 (22:22 -0400)
committerDouglas Campos <qmx@qmx.me>
Sat, 30 Sep 2017 02:34:47 +0000 (22:34 -0400)
src/librustc/ty/instance.rs
src/librustc_mir/transform/inline.rs

index fee4b292359a642a1bcddefcfa5133c87e18cfcd..89f55c57048d2be541e3f3f2c82f79dfea7875ba 100644 (file)
@@ -118,12 +118,12 @@ pub fn def_id(&self) -> DefId {
 
     /// 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);
@@ -184,6 +184,7 @@ fn resolve_closure<'a, 'tcx>(
 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>> {
@@ -194,7 +195,7 @@ fn resolve_associated_item<'a, '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:
index 426dce4da1a94bbf2d4fc3a173e93b2156eaf447..1eb8f21f80a91f2d1c0daee56c11f4425a272579 100644 (file)
@@ -78,7 +78,7 @@ fn run_pass(&self, caller_mir: &mut Mir<'tcx>) {
         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; }
@@ -88,7 +88,10 @@ fn run_pass(&self, caller_mir: &mut Mir<'tcx>) {
                 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,