about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_macros/src/query.rs9
-rw-r--r--compiler/rustc_query_impl/src/plumbing.rs3
2 files changed, 7 insertions, 5 deletions
diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs
index 55d23ba1c67..742ae964f5c 100644
--- a/compiler/rustc_macros/src/query.rs
+++ b/compiler/rustc_macros/src/query.rs
@@ -253,9 +253,6 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea
             fn cache_on_disk(#tcx: TyCtxt<'tcx>, #key: &Self::Key) -> bool {
                 #expr
             }
-
-            const TRY_LOAD_FROM_DISK: Option<fn(QueryCtxt<'tcx>, SerializedDepNodeIndex) -> Option<Self::Value>>
-                = Some(crate::plumbing::try_load_from_disk::<Self::Value>);
         }
     } else {
         quote! {
@@ -263,8 +260,6 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea
             fn cache_on_disk(_: TyCtxt<'tcx>, _: &Self::Key) -> bool {
                 false
             }
-
-            const TRY_LOAD_FROM_DISK: Option<fn(QueryCtxt<'tcx>, SerializedDepNodeIndex) -> Option<Self::Value>> = None;
         }
     };
 
@@ -333,6 +328,10 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
             remap_env_constness,
         );
 
+        if modifiers.cache.is_some() {
+            attributes.push(quote! { (cache) });
+        }
+
         // This uses the span of the query definition for the commas,
         // which can be important if we later encounter any ambiguity
         // errors with any of the numerous macro_rules! macros that
diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs
index 4ff3917e113..e38de2a0e40 100644
--- a/compiler/rustc_query_impl/src/plumbing.rs
+++ b/compiler/rustc_query_impl/src/plumbing.rs
@@ -412,6 +412,9 @@ macro_rules! define_queries {
         impl<'tcx> QueryDescription<QueryCtxt<'tcx>> for queries::$name<'tcx> {
             rustc_query_description! { $name }
 
+            const TRY_LOAD_FROM_DISK: Option<fn(QueryCtxt<'tcx>, SerializedDepNodeIndex) -> Option<Self::Value>>
+                = should_ever_cache_on_disk!([$($modifiers)*]);
+
             type Cache = query_storage::$name<'tcx>;
 
             #[inline(always)]