about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan MacKenzie <ecstaticmorse@gmail.com>2020-04-10 13:54:06 -0700
committerDylan MacKenzie <ecstaticmorse@gmail.com>2020-04-11 15:18:51 -0700
commitbeeacdb2a7165b90ee3ed1e8221c9eaad6b010ea (patch)
treef14bf4fb2066747be3a8433c0ba75f3e982f79b3 /src
parentfd8cf3c5e3adffc5ef147c8a55d3532481172c42 (diff)
downloadrust-beeacdb2a7165b90ee3ed1e8221c9eaad6b010ea.tar.gz
rust-beeacdb2a7165b90ee3ed1e8221c9eaad6b010ea.zip
Use custom trait instead of `Into`
Diffstat (limited to 'src')
-rw-r--r--src/librustc_middle/ty/query/mod.rs20
-rw-r--r--src/librustc_middle/ty/query/plumbing.rs6
2 files changed, 23 insertions, 3 deletions
diff --git a/src/librustc_middle/ty/query/mod.rs b/src/librustc_middle/ty/query/mod.rs
index 9986eb88dc3..9f04cff4d2f 100644
--- a/src/librustc_middle/ty/query/mod.rs
+++ b/src/librustc_middle/ty/query/mod.rs
@@ -189,3 +189,23 @@ pub fn force_from_dep_node<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> bool
 pub(crate) fn try_load_from_on_disk_cache<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) {
     rustc_dep_node_try_load_from_on_disk_cache!(dep_node, tcx)
 }
+
+/// An analogue of the `Into` trait that's intended only for query paramaters.
+///
+/// This exists to allow queries to accept either `DefId` or `LocalDefId` while requiring that the
+/// user call `to_def_id` to convert between them everywhere else.
+pub trait IntoQueryParam<P> {
+    fn into_query_param(self) -> P;
+}
+
+impl<P> IntoQueryParam<P> for P {
+    fn into_query_param(self) -> P {
+        self
+    }
+}
+
+impl IntoQueryParam<DefId> for LocalDefId {
+    fn into_query_param(self) -> DefId {
+        self.to_def_id()
+    }
+}
diff --git a/src/librustc_middle/ty/query/plumbing.rs b/src/librustc_middle/ty/query/plumbing.rs
index f3a49438f5b..068322b08b7 100644
--- a/src/librustc_middle/ty/query/plumbing.rs
+++ b/src/librustc_middle/ty/query/plumbing.rs
@@ -243,7 +243,7 @@ macro_rules! define_queries {
 }
 
 macro_rules! query_helper_param_ty {
-    (DefId) => { impl Into<DefId> };
+    (DefId) => { impl IntoQueryParam<DefId> };
     ($K:ty) => { $K };
 }
 
@@ -386,7 +386,7 @@ macro_rules! define_queries_inner {
             $($(#[$attr])*
             #[inline(always)]
             pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
-                ensure_query::<queries::$name<'_>, _>(self.tcx, key.into())
+                ensure_query::<queries::$name<'_>, _>(self.tcx, key.into_query_param())
             })*
         }
 
@@ -464,7 +464,7 @@ macro_rules! define_queries_inner {
             $($(#[$attr])*
             #[inline(always)]
             pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V {
-                get_query::<queries::$name<'_>, _>(self.tcx, self.span, key.into())
+                get_query::<queries::$name<'_>, _>(self.tcx, self.span, key.into_query_param())
             })*
         }