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.
This commit is contained in:
Zalathar
2026-03-15 13:17:09 +11:00
parent 1038ed1bbc
commit e8ebfcaa2e
3 changed files with 4 additions and 7 deletions
+2 -5
View File
@@ -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 {
@@ -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()))
+1 -1
View File
@@ -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! }