Skip to content

Use less #[macro_use] in the query system#153897

Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
Zalathar:use-macro
Mar 15, 2026
Merged

Use less #[macro_use] in the query system#153897
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
Zalathar:use-macro

Conversation

@Zalathar
Copy link
Copy Markdown
Member

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 a pub(crate) use after 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::QueryVTable or moving the big callback macro out of rustc_middle::query::plumbing. I think it makes sense to make this change first, to make other module-juggling tasks easier.

r? nnethercote (or compiler)

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.
@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 15, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 15, 2026
@nnethercote
Copy link
Copy Markdown
Contributor

I don't have much of an opinion one way or another here. I'll defer to someone who knows more about macros:

r? @petrochenkov

@rustbot rustbot assigned petrochenkov and unassigned nnethercote Mar 15, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Mar 15, 2026

📌 Commit e8ebfca has been approved by petrochenkov

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 15, 2026
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`)
@rust-bors rust-bors Bot merged commit e167b9b into rust-lang:main Mar 15, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 15, 2026
@Zalathar Zalathar deleted the use-macro branch March 15, 2026 22:27
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`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants