Rollup merge of #155475 - cijiugechu:missing-tokens, r=jieyouxu

Make reparsed guard metavars collect tokens

This should avoid missing tokens.

Closes rust-lang/rust#155333
This commit is contained in:
Jonathan Brouwer
2026-04-20 18:57:03 +02:00
committed by GitHub
3 changed files with 27 additions and 1 deletions
+3 -1
View File
@@ -3464,7 +3464,9 @@ pub(super) fn parse_arm(&mut self) -> PResult<'a, Arm> {
}
pub(crate) fn eat_metavar_guard(&mut self) -> Option<Box<Guard>> {
self.eat_metavar_seq(MetaVarKind::Guard, |this| this.parse_match_arm_guard()).flatten()
self.eat_metavar_seq(MetaVarKind::Guard, |this| {
this.expect_match_arm_guard(ForceCollect::Yes)
})
}
fn parse_match_arm_guard(&mut self) -> PResult<'a, Option<Box<Guard>>> {
@@ -0,0 +1,10 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/155333>
#![feature(macro_guard_matcher)]
fn main() {
macro_rules! m {
($g : guard) => {
m!($g) //~ ERROR recursion limit reached while expanding `m!`
};
}
m!(if x)
}
@@ -0,0 +1,14 @@
error: recursion limit reached while expanding `m!`
--> $DIR/macro-guard-matcher-recursion.rs:6:13
|
LL | m!($g)
| ^^^^^^
...
LL | m!(if x)
| -------- in this macro invocation
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`macro_guard_matcher_recursion`)
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 1 previous error