--- /dev/null
+// run-pass
+#![allow(unused_mut)]
+// 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 non-error cases and making sure the correct number of repetitions happen.
+
+// edition:2015
+
+macro_rules! foo {
+ ($($a:ident)? ; $num:expr) => { {
+ let mut x = 0;
+
+ $(
+ x += $a;
+ )?
+
+ assert_eq!(x, $num);
+ } }
+}
+
+pub fn main() {
+ let a = 1;
+
+ // accept 0 or 1 repetitions
+ foo!( ; 0);
+ foo!(a ; 1);
+}
--- /dev/null
+// run-pass
+#![allow(unused_mut)]
+// 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 non-error cases and making sure the correct number of repetitions happen.
+
+// edition:2018
+
+macro_rules! foo {
+ ($($a:ident)? ; $num:expr) => { {
+ let mut x = 0;
+
+ $(
+ x += $a;
+ )?
+
+ assert_eq!(x, $num);
+ } }
+}
+
+pub fn main() {
+ let a = 1;
+
+ // accept 0 or 1 repetitions
+ foo!( ; 0);
+ foo!(a ; 1);
+}
+++ /dev/null
-// run-pass
-#![allow(unused_mut)]
-// 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 non-error cases and making sure the correct number of repetitions happen.
-
-// edition:2018
-
-macro_rules! foo {
- ($($a:ident)? ; $num:expr) => { {
- let mut x = 0;
-
- $(
- x += $a;
- )?
-
- assert_eq!(x, $num);
- } }
-}
-
-pub fn main() {
- let a = 1;
-
- // accept 0 or 1 repetitions
- foo!( ; 0);
- foo!(a ; 1);
-}
#![allow(unused_macros)]
macro_rules! assign {
- (($($a:tt)*) = ($($b:tt))*) => { //~ ERROR expected `*` or `+`
+ (($($a:tt)*) = ($($b:tt))*) => { //~ ERROR expected one of: `*`, `+`, or `?`
$($a)* = $($b)*
}
}
-error: expected `*` or `+`
+error: expected one of: `*`, `+`, or `?`
--> $DIR/issue-39388.rs:4:22
|
LL | (($($a:tt)*) = ($($b:tt))*) => {
+++ /dev/null
-// Test behavior of `?` macro _kleene op_ under the 2015 edition. Namely, it doesn't exist.
-
-// edition:2015
-
-macro_rules! bar {
- ($(a)?) => {} //~ERROR expected `*` or `+`
-}
-
-macro_rules! baz {
- ($(a),?) => {} //~ERROR expected `*` or `+`
-}
-
-fn main() {}
+++ /dev/null
-error: expected `*` or `+`
- --> $DIR/macro-at-most-once-rep-2015-ques-rep.rs:6:10
- |
-LL | ($(a)?) => {}
- | ^
- |
- = note: `?` is not a macro repetition operator in the 2015 edition, but is accepted in the 2018 edition
-
-error: expected `*` or `+`
- --> $DIR/macro-at-most-once-rep-2015-ques-rep.rs:10:11
- |
-LL | ($(a),?) => {}
- | ^
- |
- = note: `?` is not a macro repetition operator in the 2015 edition, but is accepted in the 2018 edition
-
-error: aborting due to 2 previous errors
-
+++ /dev/null
-// Test behavior of `?` macro _separator_ under the 2015 edition. Namely, `?` can be used as a
-// separator, but you get a migration warning for the edition.
-
-// edition:2015
-// compile-pass
-
-#![warn(rust_2018_compatibility)]
-
-macro_rules! bar {
- ($(a)?*) => {} //~WARN using `?` as a separator
- //~^WARN this was previously accepted
-}
-
-macro_rules! baz {
- ($(a)?+) => {} //~WARN using `?` as a separator
- //~^WARN this was previously accepted
-}
-
-fn main() {
- bar!();
- bar!(a);
- bar!(a?a);
- bar!(a?a?a?a?a);
-
- baz!(a);
- baz!(a?a);
- baz!(a?a?a?a?a);
-}
+++ /dev/null
-warning: using `?` as a separator is deprecated and will be a hard error in an upcoming edition
- --> $DIR/macro-at-most-once-rep-2015-ques-sep.rs:10:10
- |
-LL | ($(a)?*) => {}
- | ^
- |
-note: lint level defined here
- --> $DIR/macro-at-most-once-rep-2015-ques-sep.rs:7:9
- |
-LL | #![warn(rust_2018_compatibility)]
- | ^^^^^^^^^^^^^^^^^^^^^^^
- = note: #[warn(question_mark_macro_sep)] implied by #[warn(rust_2018_compatibility)]
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
- = note: for more information, see issue #48075 <https://github.com/rust-lang/rust/issues/48075>
-
-warning: using `?` as a separator is deprecated and will be a hard error in an upcoming edition
- --> $DIR/macro-at-most-once-rep-2015-ques-sep.rs:15:10
- |
-LL | ($(a)?+) => {}
- | ^
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
- = note: for more information, see issue #48075 <https://github.com/rust-lang/rust/issues/48075>
-
--- /dev/null
+// Tests that `?` is a Kleene op and not a macro separator in the 2015 edition.
+
+// edition:2015
+
+macro_rules! foo {
+ ($(a)?) => {};
+}
+
+macro_rules! baz {
+ ($(a),?) => {}; //~ERROR the `?` macro repetition operator
+}
+
+macro_rules! barplus {
+ ($(a)?+) => {}; // ok. matches "a+" and "+"
+}
+
+macro_rules! barstar {
+ ($(a)?*) => {}; // ok. matches "a*" and "*"
+}
+
+pub fn main() {
+ foo!();
+ foo!(a);
+ foo!(a?); //~ ERROR no rules expected the token `?`
+ foo!(a?a); //~ ERROR no rules expected the token `?`
+ foo!(a?a?a); //~ ERROR no rules expected the token `?`
+
+ barplus!(); //~ERROR unexpected end of macro invocation
+ barplus!(a); //~ERROR unexpected end of macro invocation
+ barplus!(a?); //~ ERROR no rules expected the token `?`
+ barplus!(a?a); //~ ERROR no rules expected the token `?`
+ barplus!(a+);
+ barplus!(+);
+
+ barstar!(); //~ERROR unexpected end of macro invocation
+ barstar!(a); //~ERROR unexpected end of macro invocation
+ barstar!(a?); //~ ERROR no rules expected the token `?`
+ barstar!(a?a); //~ ERROR no rules expected the token `?`
+ barstar!(a*);
+ barstar!(*);
+}
--- /dev/null
+error: the `?` macro repetition operator does not take a separator
+ --> $DIR/macro-at-most-once-rep-2015.rs:10:10
+ |
+LL | ($(a),?) => {};
+ | ^
+
+error: no rules expected the token `?`
+ --> $DIR/macro-at-most-once-rep-2015.rs:24:11
+ |
+LL | macro_rules! foo {
+ | ---------------- when calling this macro
+...
+LL | foo!(a?);
+ | ^ no rules expected this token in macro call
+
+error: no rules expected the token `?`
+ --> $DIR/macro-at-most-once-rep-2015.rs:25:11
+ |
+LL | macro_rules! foo {
+ | ---------------- when calling this macro
+...
+LL | foo!(a?a);
+ | ^ no rules expected this token in macro call
+
+error: no rules expected the token `?`
+ --> $DIR/macro-at-most-once-rep-2015.rs:26:11
+ |
+LL | macro_rules! foo {
+ | ---------------- when calling this macro
+...
+LL | foo!(a?a?a);
+ | ^ no rules expected this token in macro call
+
+error: unexpected end of macro invocation
+ --> $DIR/macro-at-most-once-rep-2015.rs:28:5
+ |
+LL | macro_rules! barplus {
+ | -------------------- when calling this macro
+...
+LL | barplus!();
+ | ^^^^^^^^^^^ missing tokens in macro arguments
+
+error: unexpected end of macro invocation
+ --> $DIR/macro-at-most-once-rep-2015.rs:29:15
+ |
+LL | macro_rules! barplus {
+ | -------------------- when calling this macro
+...
+LL | barplus!(a);
+ | ^ missing tokens in macro arguments
+
+error: no rules expected the token `?`
+ --> $DIR/macro-at-most-once-rep-2015.rs:30:15
+ |
+LL | macro_rules! barplus {
+ | -------------------- when calling this macro
+...
+LL | barplus!(a?);
+ | ^ no rules expected this token in macro call
+
+error: no rules expected the token `?`
+ --> $DIR/macro-at-most-once-rep-2015.rs:31:15
+ |
+LL | macro_rules! barplus {
+ | -------------------- when calling this macro
+...
+LL | barplus!(a?a);
+ | ^ no rules expected this token in macro call
+
+error: unexpected end of macro invocation
+ --> $DIR/macro-at-most-once-rep-2015.rs:35:5
+ |
+LL | macro_rules! barstar {
+ | -------------------- when calling this macro
+...
+LL | barstar!();
+ | ^^^^^^^^^^^ missing tokens in macro arguments
+
+error: unexpected end of macro invocation
+ --> $DIR/macro-at-most-once-rep-2015.rs:36:15
+ |
+LL | macro_rules! barstar {
+ | -------------------- when calling this macro
+...
+LL | barstar!(a);
+ | ^ missing tokens in macro arguments
+
+error: no rules expected the token `?`
+ --> $DIR/macro-at-most-once-rep-2015.rs:37:15
+ |
+LL | macro_rules! barstar {
+ | -------------------- when calling this macro
+...
+LL | barstar!(a?);
+ | ^ no rules expected this token in macro call
+
+error: no rules expected the token `?`
+ --> $DIR/macro-at-most-once-rep-2015.rs:38:15
+ |
+LL | macro_rules! barstar {
+ | -------------------- when calling this macro
+...
+LL | barstar!(a?a);
+ | ^ no rules expected this token in macro call
+
+error: aborting due to 12 previous errors
+
macro_rules! foo {
{ $+ } => { //~ ERROR expected identifier, found `+`
//~^ ERROR missing fragment specifier
- $(x)(y) //~ ERROR expected `*` or `+`
+ $(x)(y) //~ ERROR expected one of: `*`, `+`, or `?`
}
}
LL | { $+ } => {
| ^
-error: expected `*` or `+`
+error: expected one of: `*`, `+`, or `?`
--> $DIR/issue-33569.rs:4:13
|
LL | $(x)(y)