From e8ebfcaa2eaa1a5ee63328181c7b587cec2fcf78 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Sun, 15 Mar 2026 13:17:09 +1100 Subject: [PATCH] Declare `rustc_with_all_queries!` as macros-2.0 Unlike `macro_rules!`, macros-2.0 macros have sensible item-like namespacing and visibility by default, which avoids the need for `#[macro_export]` and makes it easier to import the macro. The tradeoff is having to use `#[rustc_macro_transparency = "semiopaque"]` to still get macro-rules hygiene, because macros-2.0 hygiene is too strict here. --- compiler/rustc_macros/src/query.rs | 7 ++----- compiler/rustc_query_impl/src/dep_kind_vtables.rs | 2 +- compiler/rustc_query_impl/src/query_impl.rs | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index bd6ccf29b1fe..a803d86f2771 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -498,8 +498,8 @@ fn #name(#key_ty) #return_ty /// Higher-order macro that invokes the specified macro with (a) a list of all query /// signatures (including modifiers), and (b) a list of non-query names. This allows /// multiple simpler macros to each have access to these lists. - #[macro_export] - macro_rules! rustc_with_all_queries { + #[rustc_macro_transparency = "semiopaque"] // Use `macro_rules!` hygiene. + pub macro rustc_with_all_queries { ( // The macro to invoke once, on all queries and non-queries. $macro:ident! @@ -510,9 +510,6 @@ macro_rules! rustc_with_all_queries { } } } - // Re-export the macro as a normal item, so that other modules in `rustc_middle` - // can import it normally, without `#[macro_use]`. - pub(crate) use rustc_with_all_queries; // Add hints for rust-analyzer mod _analyzer_hints { diff --git a/compiler/rustc_query_impl/src/dep_kind_vtables.rs b/compiler/rustc_query_impl/src/dep_kind_vtables.rs index 34ef70f141b9..597c8b2a9e74 100644 --- a/compiler/rustc_query_impl/src/dep_kind_vtables.rs +++ b/compiler/rustc_query_impl/src/dep_kind_vtables.rs @@ -179,7 +179,7 @@ fn $name:ident($K:ty) -> $V:ty // Create an array of vtables, one for each dep kind (non-query and query). pub fn make_dep_kind_vtables<'tcx>(arena: &'tcx Arena<'tcx>) -> &'tcx [DepKindVTable<'tcx>] { let (nq_vtables, q_vtables) = - rustc_middle::rustc_with_all_queries! { define_dep_kind_vtables! }; + rustc_middle::queries::rustc_with_all_queries! { define_dep_kind_vtables! }; // Non-query vtables must come before query vtables, to match the order of `DepKind`. arena.alloc_from_iter(nq_vtables.into_iter().chain(q_vtables.into_iter())) diff --git a/compiler/rustc_query_impl/src/query_impl.rs b/compiler/rustc_query_impl/src/query_impl.rs index d5fb90871e76..23f678e1c9f7 100644 --- a/compiler/rustc_query_impl/src/query_impl.rs +++ b/compiler/rustc_query_impl/src/query_impl.rs @@ -272,4 +272,4 @@ macro_rules! for_each_query_vtable { } } -rustc_middle::rustc_with_all_queries! { define_queries! } +rustc_middle::queries::rustc_with_all_queries! { define_queries! }