Skip to content

Commit 03cb2a9

Browse files
committed
Make reparsed guard metavars collect tokens
1 parent 32e4c0e commit 03cb2a9

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3464,7 +3464,9 @@ impl<'a> Parser<'a> {
34643464
}
34653465

34663466
pub(crate) fn eat_metavar_guard(&mut self) -> Option<Box<Guard>> {
3467-
self.eat_metavar_seq(MetaVarKind::Guard, |this| this.parse_match_arm_guard()).flatten()
3467+
self.eat_metavar_seq(MetaVarKind::Guard, |this| {
3468+
this.expect_match_arm_guard(ForceCollect::Yes)
3469+
})
34683470
}
34693471

34703472
fn parse_match_arm_guard(&mut self) -> PResult<'a, Option<Box<Guard>>> {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! Regression test for <https://github.com/rust-lang/rust/issues/155333>
2+
#![feature(macro_guard_matcher)]
3+
fn main() {
4+
macro_rules! m {
5+
($g : guard) => {
6+
m!($g) //~ ERROR recursion limit reached while expanding `m!`
7+
};
8+
}
9+
m !(if x)
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: recursion limit reached while expanding `m!`
2+
--> $DIR/macro-guard-matcher-recursion.rs:6:13
3+
|
4+
LL | m!($g)
5+
| ^^^^^^
6+
...
7+
LL | m !(if x)
8+
| --------- in this macro invocation
9+
|
10+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`macro_guard_matcher_recursion`)
11+
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)