]> git.lizzy.rs Git - rust.git/commitdiff
Simplify the implementation of `rustc_queries`
authorJoshua Nelson <jnelson@cloudflare.com>
Fri, 2 Sep 2022 02:21:29 +0000 (21:21 -0500)
committerJoshua Nelson <jnelson@cloudflare.com>
Sat, 10 Sep 2022 01:16:47 +0000 (20:16 -0500)
compiler/rustc_macros/src/query.rs

index a99cba817d96e9a747569184d3cd7594f5e39571..77fb997dc48bdb6d9c1be8b8daed9fa1646e06ce 100644 (file)
@@ -344,43 +344,26 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
 
         let mut attributes = Vec::new();
 
-        // Pass on the fatal_cycle modifier
-        if let Some(fatal_cycle) = &modifiers.fatal_cycle {
-            attributes.push(quote! { (#fatal_cycle) });
-        };
-        // Pass on the arena modifier
-        if let Some(ref arena_cache) = modifiers.arena_cache {
-            attributes.push(quote! {span=> (#arena_cache) });
-        };
-        // Pass on the cycle_delay_bug modifier
-        if let Some(cycle_delay_bug) = &modifiers.cycle_delay_bug {
-            attributes.push(quote! { (#cycle_delay_bug) });
-        };
-        // Pass on the no_hash modifier
-        if let Some(no_hash) = &modifiers.no_hash {
-            attributes.push(quote! { (#no_hash) });
-        };
-        // Pass on the anon modifier
-        if let Some(anon) = &modifiers.anon {
-            attributes.push(quote! { (#anon) });
-        };
-        // Pass on the eval_always modifier
-        if let Some(eval_always) = &modifiers.eval_always {
-            attributes.push(quote! { (#eval_always) });
-        };
-        // Pass on the depth_limit modifier
-        if let Some(depth_limit) = &modifiers.depth_limit {
-            attributes.push(quote! { (#depth_limit) });
-        };
-        // Pass on the separate_provide_extern modifier
-        if let Some(separate_provide_extern) = &modifiers.separate_provide_extern {
-            attributes.push(quote! { (#separate_provide_extern) });
-        }
-        // Pass on the remap_env_constness modifier
-        if let Some(remap_env_constness) = &modifiers.remap_env_constness {
-            attributes.push(quote! { (#remap_env_constness) });
+        macro_rules! passthrough {
+            ( $( $modifier:ident ),+ $(,)? ) => {
+                $( if let Some($modifier) = &modifiers.$modifier {
+                    attributes.push(quote! { (#$modifier) });
+                }; )+
+            }
         }
 
+        passthrough!(
+            fatal_cycle,
+            arena_cache,
+            cycle_delay_bug,
+            no_hash,
+            anon,
+            eval_always,
+            depth_limit,
+            separate_provide_extern,
+            remap_env_constness,
+        );
+
         // 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