Skip to content

mbe: Use concrete type for get_unused_rule #144292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

joshtriplett
Copy link
Member

Rather than adding get_unused_rule to the TTMacroExpander trait, put
it on the concrete MacroRulesMacroExpander, and downcast to that type
via Any in order to call it.

Suggested-by: Vadim Petrochenkov vadim.petrochenkov@gmail.com

r? @petrochenkov

Rather than adding `get_unused_rule` to the `TTMacroExpander` trait, put
it on the concrete `MacroRulesMacroExpander`, and downcast to that type
via `Any` in order to call it.

Suggested-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
@rustbot rustbot added 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. labels Jul 22, 2025
@petrochenkov
Copy link
Contributor

I think this also eliminates the need in struct MacroData, which is basically SyntaxExtension + some details about MacroRulesMacroExpander specifically.
But I can cleanup that later.
@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 22, 2025

📌 Commit 551cb9f has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors 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 Jul 22, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2025
…-for-get-unused-rule, r=petrochenkov

mbe: Use concrete type for `get_unused_rule`

Rather than adding `get_unused_rule` to the `TTMacroExpander` trait, put
it on the concrete `MacroRulesMacroExpander`, and downcast to that type
via `Any` in order to call it.

Suggested-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

r? `@petrochenkov`
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2025
…-for-get-unused-rule, r=petrochenkov

mbe: Use concrete type for `get_unused_rule`

Rather than adding `get_unused_rule` to the `TTMacroExpander` trait, put
it on the concrete `MacroRulesMacroExpander`, and downcast to that type
via `Any` in order to call it.

Suggested-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

r? ``@petrochenkov``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 23, 2025
…-for-get-unused-rule, r=petrochenkov

mbe: Use concrete type for `get_unused_rule`

Rather than adding `get_unused_rule` to the `TTMacroExpander` trait, put
it on the concrete `MacroRulesMacroExpander`, and downcast to that type
via `Any` in order to call it.

Suggested-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

r? ```@petrochenkov```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 23, 2025
…-for-get-unused-rule, r=petrochenkov

mbe: Use concrete type for `get_unused_rule`

Rather than adding `get_unused_rule` to the `TTMacroExpander` trait, put
it on the concrete `MacroRulesMacroExpander`, and downcast to that type
via `Any` in order to call it.

Suggested-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

r? ````@petrochenkov````
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 23, 2025
…-for-get-unused-rule, r=petrochenkov

mbe: Use concrete type for `get_unused_rule`

Rather than adding `get_unused_rule` to the `TTMacroExpander` trait, put
it on the concrete `MacroRulesMacroExpander`, and downcast to that type
via `Any` in order to call it.

Suggested-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

r? `````@petrochenkov`````
bors added a commit that referenced this pull request Jul 23, 2025
Rollup of 10 pull requests

Successful merges:

 - #144173 (Remove tidy checks for `tests/ui/issues/`)
 - #144234 (Fix broken TLS destructors on 32-bit win7)
 - #144239 (Clean `rustc/parse/src/lexer` to improve maintainability)
 - #144247 (coretests/num: use ldexp instead of hard-coding a power of 2)
 - #144256 (Don't ICE on non-TypeId metadata within TypeId)
 - #144290 (update tests/ui/SUMMARY.md)
 - #144292 (mbe: Use concrete type for `get_unused_rule`)
 - #144298 (coverage: Enlarge empty spans during MIR instrumentation, not codegen)
 - #144311 (Add powerpc64le-unknown-linux-musl to CI rustc targets)
 - #144315 (bootstrap: add package.json and package-lock.json to dist tarball)

r? `@ghost`
`@rustbot` modify labels: rollup
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 23, 2025
…-for-get-unused-rule, r=petrochenkov

mbe: Use concrete type for `get_unused_rule`

Rather than adding `get_unused_rule` to the `TTMacroExpander` trait, put
it on the concrete `MacroRulesMacroExpander`, and downcast to that type
via `Any` in order to call it.

Suggested-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

r? ``````@petrochenkov``````
bors added a commit that referenced this pull request Jul 23, 2025
Rollup of 10 pull requests

Successful merges:

 - #144173 (Remove tidy checks for `tests/ui/issues/`)
 - #144234 (Fix broken TLS destructors on 32-bit win7)
 - #144239 (Clean `rustc/parse/src/lexer` to improve maintainability)
 - #144247 (coretests/num: use ldexp instead of hard-coding a power of 2)
 - #144256 (Don't ICE on non-TypeId metadata within TypeId)
 - #144290 (update tests/ui/SUMMARY.md)
 - #144292 (mbe: Use concrete type for `get_unused_rule`)
 - #144298 (coverage: Enlarge empty spans during MIR instrumentation, not codegen)
 - #144311 (Add powerpc64le-unknown-linux-musl to CI rustc targets)
 - #144315 (bootstrap: add package.json and package-lock.json to dist tarball)

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: x86_64-gnu-aux
@joshtriplett
Copy link
Member Author

joshtriplett commented Jul 23, 2025

@petrochenkov

I think this also eliminates the need in struct MacroData, which is basically SyntaxExtension + some details about MacroRulesMacroExpander specifically.

Insofar as we can get that data by downcasting to the concrete type and calling a method, as well? Perhaps.

One design question there: when introducing macro_rules! attr and derive rules, I'd been considering having MacroData have multiple SyntaxExtensions (e.g. a LegacyBang and an Option for an Attr). (That seems necessary because every SyntaxExtension seems to map to one and only one type of macro.)

But the nrules and macro_rules fields can probably go away, yes.

But I can cleanup that later.

I'd be happy to write the PR for that too, if I can get some feedback on the above design question.

@petrochenkov
Copy link
Contributor

I'm only saying that it is redundant right now.
If you plan to introduce some changes that will require something like it again, then it will make sense to re-add it, perhaps with a different name.

bors added a commit that referenced this pull request Jul 23, 2025
Rollup of 9 pull requests

Successful merges:

 - #144173 (Remove tidy checks for `tests/ui/issues/`)
 - #144234 (Fix broken TLS destructors on 32-bit win7)
 - #144239 (Clean `rustc/parse/src/lexer` to improve maintainability)
 - #144256 (Don't ICE on non-TypeId metadata within TypeId)
 - #144290 (update tests/ui/SUMMARY.md)
 - #144292 (mbe: Use concrete type for `get_unused_rule`)
 - #144298 (coverage: Enlarge empty spans during MIR instrumentation, not codegen)
 - #144311 (Add powerpc64le-unknown-linux-musl to CI rustc targets)
 - #144315 (bootstrap: add package.json and package-lock.json to dist tarball)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 1d0d472 into rust-lang:master Jul 23, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 23, 2025
rust-timer added a commit that referenced this pull request Jul 23, 2025
Rollup merge of #144292 - joshtriplett:mbe-use-concrete-type-for-get-unused-rule, r=petrochenkov

mbe: Use concrete type for `get_unused_rule`

Rather than adding `get_unused_rule` to the `TTMacroExpander` trait, put
it on the concrete `MacroRulesMacroExpander`, and downcast to that type
via `Any` in order to call it.

Suggested-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

r? ```````@petrochenkov```````
@joshtriplett joshtriplett deleted the mbe-use-concrete-type-for-get-unused-rule branch July 23, 2025 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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