Skip to content

Simplify macros for target-modifier and mitigation flags#155389

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Zalathar:flag-macros
Apr 20, 2026
Merged

Simplify macros for target-modifier and mitigation flags#155389
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Zalathar:flag-macros

Conversation

@Zalathar
Copy link
Copy Markdown
Member


The macros used for handling command-line flags that are “target modifiers” or “mitigations” are quite complicated, and can be significantly simplified by tweaking their syntax and by making use of ${ignore(..)} metavars.

It's possible that more code could be moved out of macros (e.g. declaring some of the enums by hand), but that can be investigated in a potential follow-up.

There should be no change to compiler behaviour.

@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 Apr 16, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 16, 2026

r? @mati865

rustbot has assigned @mati865.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 72 candidates
  • Random selection from 16 candidates

box_noalias: bool = (true, parse_bool, [TRACKED],
"emit noalias metadata for box (default: yes)"),
branch_protection: Option<BranchProtection> = (None, parse_branch_protection, [TRACKED TARGET_MODIFIER],
branch_protection: Option<BranchProtection> = (None, parse_branch_protection, [TRACKED] { TARGET_MODIFIER: BranchProtection },
Copy link
Copy Markdown
Member Author

@Zalathar Zalathar Apr 16, 2026

Choose a reason for hiding this comment

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

A limitation of the ${ignore(..)} approach is that we can't just accept a bare TARGET_MODIFIER; we have to accept some kind of variable as well (in this case an identifier).

Because of that, I took the opportunity to give the enum variants camel-case names instead of recycling the struct-field names.

View changes since the review

Comment on lines +483 to +484
$( { TARGET_MODIFIER: $tmod_variant:ident } )?
$( { MITIGATION: $mitigation_variant:ident } )?
Copy link
Copy Markdown
Member Author

@Zalathar Zalathar Apr 16, 2026

Choose a reason for hiding this comment

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

I tried a lot of different syntaxes here, and { FOO: Bar } is what I eventually settled on.

Many of the alternatives I tried ran into parse ambiguity problems.

At one point I was accepting $tmod:vis TARGET_MODIFIER to allow an empty visibility, but that ended up not working when I had to support MITIGATION at the same time.

View changes since the review

Copy link
Copy Markdown
Member

@mati865 mati865 left a comment

Choose a reason for hiding this comment

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

Looks better to me, thanks!

@bors r+

View changes since this review

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 20, 2026

📌 Commit fb27b3b has been approved by mati865

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 Apr 20, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 20, 2026
Simplify macros for target-modifier and mitigation flags

- Rebased and revised version of rust-lang#154501.
---

The macros used for handling command-line flags that are “target modifiers” or “mitigations” are quite complicated, and can be significantly simplified by tweaking their syntax and by making use of `${ignore(..)}` metavars.

It's possible that more code could be moved out of macros (e.g. declaring some of the enums by hand), but that can be investigated in a potential follow-up.

There should be no change to compiler behaviour.
rust-bors Bot pushed a commit that referenced this pull request Apr 20, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #155556 (`rust-analyzer` subtree update)
 - #152162 (Suggest returning a reference for unsized place from a closure)
 - #155389 (Simplify macros for target-modifier and mitigation flags)
 - #155553 (miri subtree update)
 - #153546 (tests/ui/extern: add annotations for reference rules)
 - #155475 (Make reparsed guard metavars collect tokens)
 - #155560 (Remove `AttributeLintKind` variants - part 4)
@rust-bors rust-bors Bot merged commit 074ed7b into rust-lang:main Apr 20, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 20, 2026
@Zalathar Zalathar deleted the flag-macros branch April 21, 2026 00:27
pull Bot pushed a commit to LeeeeeeM/miri that referenced this pull request Apr 24, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#155556 (`rust-analyzer` subtree update)
 - rust-lang/rust#152162 (Suggest returning a reference for unsized place from a closure)
 - rust-lang/rust#155389 (Simplify macros for target-modifier and mitigation flags)
 - rust-lang/rust#155553 (miri subtree update)
 - rust-lang/rust#153546 (tests/ui/extern: add annotations for reference rules)
 - rust-lang/rust#155475 (Make reparsed guard metavars collect tokens)
 - rust-lang/rust#155560 (Remove `AttributeLintKind` variants - part 4)
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.

3 participants