Skip to content

define_queries! module tweaks#153588

Open
nnethercote wants to merge 3 commits intorust-lang:mainfrom
nnethercote:define_queries-module-tweaks
Open

define_queries! module tweaks#153588
nnethercote wants to merge 3 commits intorust-lang:mainfrom
nnethercote:define_queries-module-tweaks

Conversation

@nnethercote
Copy link
Contributor

Minor module structure tweaks, trying to make define_queries! nicer and more like define_callbacks!. Details in individual commits.

r? @Zalathar

This use item lets `rustc_query_impl` use `queries::foo` to refer to
things from `rustc_middle`, which is confusing, especially within
`define_queries!`.

This commit removes it, requiring more explicit qualification of
imported things. It also removes some unnecessary leading `::`
qualifiers from `rustc_middle` mentions for consistency, conciseness,
and to spare the poor reader's eyes.
`define_queries!` currently outputs some things (including one `mod
$name` per query) into a module `query_impl`, and some things into the
crate root. This commit moves the latter things into `query_impl`. This
is (a) nicer, and (b) more closely matches what `define_callbacks!`
does.
@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 9, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2026

Zalathar is not on the review rotation at the moment.
They may take a while to respond.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2026
@nnethercote
Copy link
Contributor Author

@Zalathar: not sure if you'll like these, but I figured it's worth a try.

non_queries { $($_:tt)* }
) => {
pub(crate) mod query_impl { $(pub(crate) mod $name {
$(pub(crate) mod $name {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we leave behind a comment mentioning the module name, that gives us most of the readability/searchability benefits of declaring the module inside the macro, while still improving consistency with rustc_middle and avoiding extra nesting.

// This macro expects to be expanded into `mod query_impl` in the crate root.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. I've added this comment.

This:
- reduces the amount of stuff inside `define_queries!`
- makes `define_queries!` look more like `define_callbacks!`

Also, I want to improve the formatting of `define_queries!` and this
will avoid one level of indentation.
@nnethercote nnethercote force-pushed the define_queries-module-tweaks branch from b045589 to ca85c9b Compare March 9, 2026 05:49
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-review Status: Awaiting review from the assignee but also interested parties. 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.

3 participants