]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_middle/src/ty/query.rs
Auto merge of #93752 - eholk:drop-tracking-break-continue, r=nikomatsakis
[rust.git] / compiler / rustc_middle / src / ty / query.rs
index 040e642b7b6d6f102a7467b4748b8ff0935ca0fe..1688e59cdd12fe89fd7ba6858a9706691e2dc1f9 100644 (file)
@@ -106,6 +106,12 @@ pub fn try_mark_green(self, dep_node: &dep_graph::DepNode) -> bool {
 #[inline(always)]
 fn noop<T>(_: &T) {}
 
+/// Helper to ensure that queries only return `Copy` types.
+#[inline(always)]
+fn copy<T: Copy>(x: &T) -> T {
+    *x
+}
+
 macro_rules! query_helper_param_ty {
     (DefId) => { impl IntoQueryParam<DefId> };
     ($K:ty) => { $K };
@@ -243,7 +249,7 @@ pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<$
                 let key = key.into_query_param();
                 opt_remap_env_constness!([$($modifiers)*][key]);
 
-                let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, Clone::clone);
+                let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, copy);
 
                 let lookup = match cached {
                     Ok(value) => return value,
@@ -347,6 +353,13 @@ fn into_query_param(self) -> P {
         }
     }
 
+    impl<'a, P: Copy> IntoQueryParam<P> for &'a P {
+        #[inline(always)]
+        fn into_query_param(self) -> P {
+            *self
+        }
+    }
+
     impl IntoQueryParam<DefId> for LocalDefId {
         #[inline(always)]
         fn into_query_param(self) -> DefId {