Skip to content

Commit b7c9687

Browse files
committed
Simplify the implementation of rustc_queries
1 parent fb0c36a commit b7c9687

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

compiler/rustc_macros/src/query.rs

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -344,43 +344,26 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
344344

345345
let mut attributes = Vec::new();
346346

347-
// Pass on the fatal_cycle modifier
348-
if let Some(fatal_cycle) = &modifiers.fatal_cycle {
349-
attributes.push(quote! { (#fatal_cycle) });
350-
};
351-
// Pass on the arena modifier
352-
if let Some(ref arena_cache) = modifiers.arena_cache {
353-
attributes.push(quote! {span=> (#arena_cache) });
354-
};
355-
// Pass on the cycle_delay_bug modifier
356-
if let Some(cycle_delay_bug) = &modifiers.cycle_delay_bug {
357-
attributes.push(quote! { (#cycle_delay_bug) });
358-
};
359-
// Pass on the no_hash modifier
360-
if let Some(no_hash) = &modifiers.no_hash {
361-
attributes.push(quote! { (#no_hash) });
362-
};
363-
// Pass on the anon modifier
364-
if let Some(anon) = &modifiers.anon {
365-
attributes.push(quote! { (#anon) });
366-
};
367-
// Pass on the eval_always modifier
368-
if let Some(eval_always) = &modifiers.eval_always {
369-
attributes.push(quote! { (#eval_always) });
370-
};
371-
// Pass on the depth_limit modifier
372-
if let Some(depth_limit) = &modifiers.depth_limit {
373-
attributes.push(quote! { (#depth_limit) });
374-
};
375-
// Pass on the separate_provide_extern modifier
376-
if let Some(separate_provide_extern) = &modifiers.separate_provide_extern {
377-
attributes.push(quote! { (#separate_provide_extern) });
378-
}
379-
// Pass on the remap_env_constness modifier
380-
if let Some(remap_env_constness) = &modifiers.remap_env_constness {
381-
attributes.push(quote! { (#remap_env_constness) });
347+
macro_rules! passthrough {
348+
( $( $modifier:ident ),+ $(,)? ) => {
349+
$( if let Some($modifier) = &modifiers.$modifier {
350+
attributes.push(quote! { (#$modifier) });
351+
}; )+
352+
}
382353
}
383354

355+
passthrough!(
356+
fatal_cycle,
357+
arena_cache,
358+
cycle_delay_bug,
359+
no_hash,
360+
anon,
361+
eval_always,
362+
depth_limit,
363+
separate_provide_extern,
364+
remap_env_constness,
365+
);
366+
384367
// This uses the span of the query definition for the commas,
385368
// which can be important if we later encounter any ambiguity
386369
// errors with any of the numerous macro_rules! macros that

0 commit comments

Comments
 (0)