Tracking Issue for `guard` macro fragment specifier
@SpriteOvO is already working on this.
Since Feb 25, 2026.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
This is a tracking issue for the feature "guard macro fragment specifier" accepted in https://github.com/rust-lang/rust/pull/152832#issuecomment-3953476605.
The feature gate for the issue is #![feature(macro_guard_matcher)].
Introduce a new macro fragment specifier guard to match MatchArmGuard, to make it easier for macro authors to match the recently stabilized if_let_guard feature (#51114).
This resolves #152313, because we either introduce a new :guard matcher or must refactor matches! and assert_matches! into built-in macros. Considering that more users will benefit from :guard, we choose to do so.
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.
Steps
- Implement the
:guardfragment specifier formacro_rulesanddecl_macro
#153702 - Use
:guardinmathces!andassert_matches!to supportif-letguards
#156025 - Adjust documentation (see instructions on rustc-dev-guide)
- Stabilization PR (see instructions on rustc-dev-guide)
Unresolved Questions
- (fmease writing) Should
{really be in the follow set? I'm not quite sure it should.- The condition of match guards can be an "unrestricted" expressions precisely because the guard can only be followed by
=>contrary to the conditions ofif&whileexpressions and the iterator offorloops which are expressions without struct expressions. - So while
if S {}successfully parses as an expression (namely asif (S) {}), macro matcher$g:guard {}currently rejectsif S {}as input because it parsesif (S {})and looks for extra{}which aren't there of course.
- The condition of match guards can be an "unrestricted" expressions precisely because the guard can only be followed by
Implementation history
- #152832
The initial attempt used:ttto match if-let guards, but:ttgreedily captured the trailing comma and the assertion message. So we decide to introduce a new:guardmatcher. - #153702
- #155182
- #155475
- #156025
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.