X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_middle%2Fsrc%2Fty%2Fquery.rs;h=1688e59cdd12fe89fd7ba6858a9706691e2dc1f9;hb=0c3f0cddde337ef596b45a8ac53aae4c8845237b;hp=040e642b7b6d6f102a7467b4748b8ff0935ca0fe;hpb=8429dcdb79b35182036e8de574287a7acc4b14d8;p=rust.git diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index 040e642b7b6..1688e59cdd1 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -106,6 +106,12 @@ pub fn try_mark_green(self, dep_node: &dep_graph::DepNode) -> bool { #[inline(always)] fn noop(_: &T) {} +/// Helper to ensure that queries only return `Copy` types. +#[inline(always)] +fn copy(x: &T) -> T { + *x +} + macro_rules! query_helper_param_ty { (DefId) => { impl IntoQueryParam }; ($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

for &'a P { + #[inline(always)] + fn into_query_param(self) -> P { + *self + } + } + impl IntoQueryParam for LocalDefId { #[inline(always)] fn into_query_param(self) -> DefId {