about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_middle/mir/query.rs12
-rw-r--r--src/librustc_middle/query/mod.rs4
-rw-r--r--src/librustc_mir/const_eval/eval_queries.rs2
-rw-r--r--src/librustc_mir/interpret/eval_context.rs6
-rw-r--r--src/librustc_mir/transform/mod.rs12
5 files changed, 20 insertions, 16 deletions
diff --git a/src/librustc_middle/mir/query.rs b/src/librustc_middle/mir/query.rs
index 76b8ac4e80a..884067347a6 100644
--- a/src/librustc_middle/mir/query.rs
+++ b/src/librustc_middle/mir/query.rs
@@ -1,5 +1,6 @@
 //! Values computed by queries that use MIR.
 
+use crate::mir::{Body, Promoted};
 use crate::ty::{self, Ty, TyCtxt};
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::sync::Lrc;
@@ -343,4 +344,15 @@ impl<'tcx> TyCtxt<'tcx> {
             self.mir_const_qualif(def.did)
         }
     }
+
+    pub fn promoted_mir_of_opt_const_arg(
+        self,
+        def: ty::WithOptParam<DefId>,
+    ) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
+        if let Some((did, param_did)) = def.as_const_arg() {
+            self.promoted_mir_of_const_arg((did, param_did))
+        } else {
+            self.promoted_mir(def.did)
+        }
+    }
 }
diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs
index 76702fab9dc..8c4b8cd1c8f 100644
--- a/src/librustc_middle/query/mod.rs
+++ b/src/librustc_middle/query/mod.rs
@@ -277,11 +277,11 @@ rustc_queries! {
             cache_on_disk_if { key.is_local() }
         }
         query promoted_mir_of_const_arg(
-            key: ty::WithOptParam<LocalDefId>
+            key: (LocalDefId, DefId)
         ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
             desc {
                 |tcx| "optimizing promoted MIR for the const argument `{}`",
-                tcx.def_path_str(key.did.to_def_id()),
+                tcx.def_path_str(key.0.to_def_id()),
             }
         }
     }
diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs
index 38894398343..cec7f1bcb9d 100644
--- a/src/librustc_mir/const_eval/eval_queries.rs
+++ b/src/librustc_mir/const_eval/eval_queries.rs
@@ -360,7 +360,7 @@ pub fn const_eval_raw_provider<'tcx>(
                     // deny-by-default lint
                     _ => {
                         if let Some(p) = cid.promoted {
-                            let span = tcx.promoted_mir_of_const_arg(def)[p].span;
+                            let span = tcx.promoted_mir_of_opt_const_arg(def.to_global())[p].span;
                             if let err_inval!(ReferencedConstant) = err.error {
                                 err.report_as_error(
                                     tcx.at(span),
diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs
index 9cbc6d4dcea..c59b7c98e98 100644
--- a/src/librustc_mir/interpret/eval_context.rs
+++ b/src/librustc_mir/interpret/eval_context.rs
@@ -406,11 +406,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
         }
         trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);
         if let Some(promoted) = promoted {
-            return if let Some(def) = def.as_local() {
-                Ok(&self.tcx.promoted_mir_of_const_arg(def)[promoted])
-            } else {
-                Ok(&self.tcx.promoted_mir(def.did)[promoted])
-            };
+            return Ok(&self.tcx.promoted_mir_of_opt_const_arg(def)[promoted]);
         }
         match instance {
             ty::InstanceDef::Item(def) => {
diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs
index fdcf36a3162..f2d6efae019 100644
--- a/src/librustc_mir/transform/mod.rs
+++ b/src/librustc_mir/transform/mod.rs
@@ -62,12 +62,8 @@ pub(crate) fn provide(providers: &mut Providers) {
         promoted_mir: |tcx, def_id| {
             promoted_mir(tcx, ty::WithOptParam::dummy(def_id.expect_local()))
         },
-        promoted_mir_of_const_arg: |tcx, def| {
-            if def.param_did.is_none() {
-                tcx.promoted_mir(def.did.to_def_id())
-            } else {
-                promoted_mir(tcx, def)
-            }
+        promoted_mir_of_const_arg: |tcx, (did, param_did)| {
+            promoted_mir(tcx, ty::WithOptParam { did, param_did: Some(param_did) })
         },
         ..*providers
     };
@@ -525,8 +521,8 @@ fn promoted_mir<'tcx>(
     def: ty::WithOptParam<LocalDefId>,
 ) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
     if def.param_did.is_none() {
-        if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) {
-            return tcx.promoted_mir_of_const_arg(ty::WithOptParam { param_did, ..def });
+        if let Some(param_did) = tcx.opt_const_param_of(def.did) {
+            return tcx.promoted_mir_of_const_arg((def.did, param_did));
         }
     }