Skip to content

Simplify macros for target-modifier and mitigation flags#155389

Open
Zalathar wants to merge 1 commit intorust-lang:mainfrom
Zalathar:flag-macros
Open

Simplify macros for target-modifier and mitigation flags#155389
Zalathar wants to merge 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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