mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-29 04:00:16 -04:00
Make the expansion of guard metavars begin guard non-terminals
This commit is contained in:
@@ -3464,11 +3464,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
pub(crate) fn eat_metavar_guard(&mut self) -> Option<Box<Guard>> {
|
||||
self.eat_metavar_seq_with_matcher(
|
||||
|mv_kind| matches!(mv_kind, MetaVarKind::Guard),
|
||||
|this| this.parse_match_arm_guard(),
|
||||
)
|
||||
.flatten()
|
||||
self.eat_metavar_seq(MetaVarKind::Guard, |this| this.parse_match_arm_guard()).flatten()
|
||||
}
|
||||
|
||||
fn parse_match_arm_guard(&mut self) -> PResult<'a, Option<Box<Guard>>> {
|
||||
|
||||
@@ -105,7 +105,10 @@ impl<'a> Parser<'a> {
|
||||
token::Lifetime(..) | token::NtLifetime(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
NonterminalKind::Guard => token.is_keyword(kw::If),
|
||||
NonterminalKind::Guard => match token.kind {
|
||||
token::OpenInvisible(InvisibleOrigin::MetaVar(MetaVarKind::Guard)) => true,
|
||||
_ => token.is_keyword(kw::If),
|
||||
},
|
||||
NonterminalKind::TT | NonterminalKind::Item | NonterminalKind::Stmt => {
|
||||
token.kind.close_delim().is_none()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
fn main() {
|
||||
macro_rules! m {
|
||||
($x:guard) => {};
|
||||
($g:guard) => {};
|
||||
}
|
||||
|
||||
// Accepts
|
||||
@@ -14,4 +14,12 @@ fn main() {
|
||||
|
||||
// Rejects
|
||||
m!(let Some(x) = Some(1)); //~ERROR no rules expected keyword `let`
|
||||
|
||||
macro_rules! m_m {
|
||||
($g:guard) => { m!($g); };
|
||||
}
|
||||
|
||||
// Accepted since `m` recognizes that the sequence produced by the expansion of
|
||||
// metavar `$g` "begins" (i.e., is) a guard since it's of kind `guard`.
|
||||
m_m!(if true);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ LL | macro_rules! m {
|
||||
LL | m!(let Some(x) = Some(1));
|
||||
| ^^^ no rules expected this token in macro call
|
||||
|
|
||||
note: while trying to match meta-variable `$x:guard`
|
||||
note: while trying to match meta-variable `$g:guard`
|
||||
--> $DIR/macro-guard-matcher.rs:5:10
|
||||
|
|
||||
LL | ($x:guard) => {};
|
||||
LL | ($g:guard) => {};
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
Reference in New Issue
Block a user