Skip to content

Make the expansion of guard metavars begin guard non-terminals#155182

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
fmease:guard-exp-begins-guard
Apr 13, 2026
Merged

Make the expansion of guard metavars begin guard non-terminals#155182
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
fmease:guard-exp-begins-guard

Conversation

@fmease
Copy link
Copy Markdown
Member

@fmease fmease commented Apr 12, 2026

While investigating something unrelated, I noticed a bug in the impl of unstable feature macro_guard_matcher (tracking issue: #153104). Namely, the following doesn't compile:

#![feature(macro_guard_matcher)]

macro_rules! a { ($guard:guard) => { b!($guard); }; }
macro_rules! b { ($guard:guard) => {}; }
a!(if true);
error: no rules expected `guard` metavariable
 --> src/lib.rs:3:41
  |
3 | macro_rules! a { ($guard:guard) => { b!($guard); }; }
  |                                         ^^^^^^ no rules expected this token in macro call
4 | macro_rules! b { ($guard:guard) => {}; }
  | -------------- when calling this macro
5 | a!(if true);
  | ----------- in this macro invocation
  |
note: while trying to match meta-variable `$guard:guard`
 --> src/lib.rs:4:19
  |
4 | macro_rules! b { ($guard:guard) => {}; }
  |                   ^^^^^^^^^^^^
  = note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info)

While I'm still skeptical of guard fragment specifiers in general (although I can't quite pinpoint why), I figured I should fix this issue.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 12, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 12, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

r? @petrochenkov

rustbot has assigned @petrochenkov.
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 69 candidates
  • Random selection from 11 candidates

Comment thread compiler/rustc_parse/src/parser/expr.rs
@petrochenkov
Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 13, 2026

📌 Commit fc2c72c has been approved by petrochenkov

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 13, 2026
rust-bors Bot pushed a commit that referenced this pull request Apr 13, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #155227 (`rust-analyzer` subtree update)
 - #153335 (Add #![unstable_removed(..)] attribute to track removed features)
 - #154932 (Handle RTN projections in assoc type restriction diagnostics)
 - #155096 (delegation: support proper interaction of user-specified args and impl Traits)
 - #155106 (cg_llvm: scalable vectors with `simd_cast` and `simd_select`)
 - #155140 (add regression test for OpenOptionsExt downstream compat)
 - #155182 (Make the expansion of guard metavars begin guard non-terminals)
 - #155226 (delegation: revert execution of hir_crate_items before delayed lowering)
 - #153997 (Use closures more consistently in `dep_graph.rs`.)
 - #155003 (update thin-vec)
@rust-bors rust-bors Bot merged commit 49b5708 into rust-lang:main Apr 13, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 13, 2026
rust-timer added a commit that referenced this pull request Apr 13, 2026
Rollup merge of #155182 - fmease:guard-exp-begins-guard, r=petrochenkov

Make the expansion of guard metavars begin guard non-terminals

While investigating something unrelated, I noticed a bug in the impl of unstable feature `macro_guard_matcher` (tracking issue: #153104). Namely, the following doesn't compile:

```rs
#![feature(macro_guard_matcher)]

macro_rules! a { ($guard:guard) => { b!($guard); }; }
macro_rules! b { ($guard:guard) => {}; }
a!(if true);
```

```
error: no rules expected `guard` metavariable
 --> src/lib.rs:3:41
  |
3 | macro_rules! a { ($guard:guard) => { b!($guard); }; }
  |                                         ^^^^^^ no rules expected this token in macro call
4 | macro_rules! b { ($guard:guard) => {}; }
  | -------------- when calling this macro
5 | a!(if true);
  | ----------- in this macro invocation
  |
note: while trying to match meta-variable `$guard:guard`
 --> src/lib.rs:4:19
  |
4 | macro_rules! b { ($guard:guard) => {}; }
  |                   ^^^^^^^^^^^^
  = note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info)
```

---

While I'm still skeptical of `guard` fragment specifiers in general (although I can't quite pinpoint why), I figured I should fix this issue.
@fmease fmease deleted the guard-exp-begins-guard branch April 13, 2026 18:34
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Apr 13, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#155227 (`rust-analyzer` subtree update)
 - rust-lang/rust#153335 (Add #![unstable_removed(..)] attribute to track removed features)
 - rust-lang/rust#154932 (Handle RTN projections in assoc type restriction diagnostics)
 - rust-lang/rust#155096 (delegation: support proper interaction of user-specified args and impl Traits)
 - rust-lang/rust#155106 (cg_llvm: scalable vectors with `simd_cast` and `simd_select`)
 - rust-lang/rust#155140 (add regression test for OpenOptionsExt downstream compat)
 - rust-lang/rust#155182 (Make the expansion of guard metavars begin guard non-terminals)
 - rust-lang/rust#155226 (delegation: revert execution of hir_crate_items before delayed lowering)
 - rust-lang/rust#153997 (Use closures more consistently in `dep_graph.rs`.)
 - rust-lang/rust#155003 (update thin-vec)
github-actions Bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Apr 16, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#155227 (`rust-analyzer` subtree update)
 - rust-lang/rust#153335 (Add #![unstable_removed(..)] attribute to track removed features)
 - rust-lang/rust#154932 (Handle RTN projections in assoc type restriction diagnostics)
 - rust-lang/rust#155096 (delegation: support proper interaction of user-specified args and impl Traits)
 - rust-lang/rust#155106 (cg_llvm: scalable vectors with `simd_cast` and `simd_select`)
 - rust-lang/rust#155140 (add regression test for OpenOptionsExt downstream compat)
 - rust-lang/rust#155182 (Make the expansion of guard metavars begin guard non-terminals)
 - rust-lang/rust#155226 (delegation: revert execution of hir_crate_items before delayed lowering)
 - rust-lang/rust#153997 (Use closures more consistently in `dep_graph.rs`.)
 - rust-lang/rust#155003 (update thin-vec)
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