88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11+ // The logic for parsing Kleene operators in macros has a special case to disambiguate `?`.
12+ // Specifically, `$(pat)?` is the ZeroOrOne operator whereas `$(pat)?+` or `$(pat)?*` are the
13+ // ZeroOrMore and OneOrMore operators using `?` as a separator. These tests are intended to
14+ // exercise that logic in the macro parser.
15+ //
16+ // Moreover, we also throw in some tests for using a separator with `?`, which is meaningless but
17+ // included for consistency with `+` and `*`.
18+ //
19+ // This test focuses on error cases.
20+
1121#![ feature( macro_at_most_once_rep) ]
1222
1323macro_rules! foo {
@@ -18,10 +28,14 @@ macro_rules! baz {
1828 ( $( a) ,?) => { } // comma separator is meaningless for `?`
1929}
2030
21- macro_rules! bar {
31+ macro_rules! barplus {
2232 ( $( a) ?+) => { }
2333}
2434
35+ macro_rules! barstar {
36+ ( $( a) ?* ) => { }
37+ }
38+
2539pub fn main ( ) {
2640 foo ! ( a?a?a) ; //~ ERROR no rules expected the token `?`
2741 foo ! ( a?a) ; //~ ERROR no rules expected the token `?`
@@ -33,6 +47,7 @@ pub fn main() {
3347 baz ! ( a?a?a, ) ; //~ ERROR no rules expected the token `?`
3448 baz ! ( a?a, ) ; //~ ERROR no rules expected the token `?`
3549 baz ! ( a?, ) ; //~ ERROR no rules expected the token `?`
36- bar ! ( ) ; //~ ERROR unexpected end of macro invocation
37- bar ! ( a?) ; //~ ERROR unexpected end of macro invocation
50+ barplus ! ( ) ; //~ ERROR unexpected end of macro invocation
51+ barplus ! ( a?) ; //~ ERROR unexpected end of macro invocation
52+ barstar ! ( a?) ; //~ ERROR unexpected end of macro invocation
3853}
0 commit comments