]> git.lizzy.rs Git - rust.git/blobdiff - src/test/ui/macros/macro-at-most-once-rep-ambig.rs
No separator for `?`. No `?` as a separator.
[rust.git] / src / test / ui / macros / macro-at-most-once-rep-ambig.rs
index a5660f8b41f8da43aeeea29deefa8607dc764bf4..63827ffeed045aed6a2fcc980a80ca610ef11e8c 100644 (file)
@@ -8,30 +8,26 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// The logic for parsing Kleene operators in macros has a special case to disambiguate `?`.
-// Specifically, `$(pat)?` is the ZeroOrOne operator whereas `$(pat)?+` or `$(pat)?*` are the
-// ZeroOrMore and OneOrMore operators using `?` as a separator. These tests are intended to
-// exercise that logic in the macro parser.
-//
-// Moreover, we also throw in some tests for using a separator with `?`, which is meaningless but
-// included for consistency with `+` and `*`.
-//
-// This test focuses on error cases.
+// Tests the behavior of various Kleene operators in macros with respect to `?` terminals. In
+// particular, `?` in the position of a separator and of a Kleene operator is tested.
 
 #![feature(macro_at_most_once_rep)]
 
+// should match `` and `a`
 macro_rules! foo {
     ($(a)?) => {}
 }
 
 macro_rules! baz {
-    ($(a),?) => {} // comma separator is meaningless for `?`
+    ($(a),?) => {} //~ ERROR `?` macro repetition does not allow a separator
 }
 
+// should match `+` and `a+`
 macro_rules! barplus {
     ($(a)?+) => {}
 }
 
+// should match `*` and `a*`
 macro_rules! barstar {
     ($(a)?*) => {}
 }
@@ -40,14 +36,14 @@ pub fn main() {
     foo!(a?a?a); //~ ERROR no rules expected the token `?`
     foo!(a?a); //~ ERROR no rules expected the token `?`
     foo!(a?); //~ ERROR no rules expected the token `?`
-    baz!(a?a?a); //~ ERROR no rules expected the token `?`
-    baz!(a?a); //~ ERROR no rules expected the token `?`
-    baz!(a?); //~ ERROR no rules expected the token `?`
-    baz!(a,); //~ ERROR unexpected end of macro invocation
-    baz!(a?a?a,); //~ ERROR no rules expected the token `?`
-    baz!(a?a,); //~ ERROR no rules expected the token `?`
-    baz!(a?,); //~ ERROR no rules expected the token `?`
     barplus!(); //~ ERROR unexpected end of macro invocation
-    barplus!(a?); //~ ERROR unexpected end of macro invocation
-    barstar!(a?); //~ ERROR unexpected end of macro invocation
+    barstar!(); //~ ERROR unexpected end of macro invocation
+    barplus!(a?); //~ ERROR no rules expected the token `?`
+    barplus!(a); //~ ERROR unexpected end of macro invocation
+    barstar!(a?); //~ ERROR no rules expected the token `?`
+    barstar!(a); //~ ERROR unexpected end of macro invocation
+    barplus!(+); // ok
+    barstar!(*); // ok
+    barplus!(a); // ok
+    barstar!(a*); // ok
 }