Use less #[macro_use] in the query system#153897
Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom Mar 15, 2026
Merged
Use less #[macro_use] in the query system#153897rust-bors[bot] merged 2 commits intorust-lang:mainfrom
#[macro_use] in the query system#153897rust-bors[bot] merged 2 commits intorust-lang:mainfrom
Conversation
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.
Contributor
|
I don't have much of an opinion one way or another here. I'll defer to someone who knows more about macros: |
Contributor
|
@bors r+ rollup |
Contributor
rust-bors Bot
pushed a commit
that referenced
this pull request
Mar 15, 2026
Rollup of 6 pull requests Successful merges: - #153870 (docs: remove stale reference to `check_let_chain`) - #153881 (Provide more context on type errors in const context) - #153887 (Turn label into structured suggestion for `.as_ref()` and `.as_mut()`) - #153897 (Use less `#[macro_use]` in the query system) - #153914 (add test for param-env shadowing) - #153917 (compiletest: show rustdoc logs when `--no-capture`)
github-actions Bot
pushed a commit
to rust-lang/miri
that referenced
this pull request
Mar 16, 2026
Rollup of 6 pull requests Successful merges: - rust-lang/rust#153870 (docs: remove stale reference to `check_let_chain`) - rust-lang/rust#153881 (Provide more context on type errors in const context) - rust-lang/rust#153887 (Turn label into structured suggestion for `.as_ref()` and `.as_mut()`) - rust-lang/rust#153897 (Use less `#[macro_use]` in the query system) - rust-lang/rust#153914 (add test for param-env shadowing) - rust-lang/rust#153917 (compiletest: show rustdoc logs when `--no-capture`)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Macro-rules namespacing and import/export is a bit of a nightmare in general. We can tame it a bit by avoiding
#[macro_use]as much as possible, and instead putting apub(crate) useafter the macro-rules declaration to make the macro importable as a normal item.I've split this PR into two commits. The first one should hopefully be uncontroversial, while the second commit takes the extra step of declaring
rustc_with_all_queries!as a macros-2.0 macro, which gives much nicer import/export behaviour, at the expense of having to specify#[rustc_macro_transparency = "semiopaque"]to still have access to macro-rules hygiene, because the default macros-2.0 hygiene is too strict here.There should be no change to compiler behaviour.
I stumbled into this while investigating some other changes, such as re-exporting
rustc_middle::query::QueryVTableor moving the big callback macro out ofrustc_middle::query::plumbing. I think it makes sense to make this change first, to make other module-juggling tasks easier.r? nnethercote (or compiler)