]> git.lizzy.rs Git - rust.git/commitdiff
Update tests since ? macro op is supported on 2015.
authorMazdak Farrokhzad <twingoow@gmail.com>
Sat, 18 May 2019 06:24:56 +0000 (08:24 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Sun, 9 Jun 2019 02:16:34 +0000 (04:16 +0200)
13 files changed:
src/test/run-pass/macros/macro-at-most-once-rep-2015.rs [new file with mode: 0644]
src/test/run-pass/macros/macro-at-most-once-rep-2018.rs [new file with mode: 0644]
src/test/run-pass/macros/macro-at-most-once-rep.rs [deleted file]
src/test/ui/issues/issue-39388.rs
src/test/ui/issues/issue-39388.stderr
src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.rs [deleted file]
src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.stderr [deleted file]
src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.rs [deleted file]
src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.stderr [deleted file]
src/test/ui/macros/macro-at-most-once-rep-2015.rs [new file with mode: 0644]
src/test/ui/macros/macro-at-most-once-rep-2015.stderr [new file with mode: 0644]
src/test/ui/parser/macro/issue-33569.rs
src/test/ui/parser/macro/issue-33569.stderr

diff --git a/src/test/run-pass/macros/macro-at-most-once-rep-2015.rs b/src/test/run-pass/macros/macro-at-most-once-rep-2015.rs
new file mode 100644 (file)
index 0000000..72dfc11
--- /dev/null
@@ -0,0 +1,33 @@
+// 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);
+}
diff --git a/src/test/run-pass/macros/macro-at-most-once-rep-2018.rs b/src/test/run-pass/macros/macro-at-most-once-rep-2018.rs
new file mode 100644 (file)
index 0000000..582ef08
--- /dev/null
@@ -0,0 +1,33 @@
+// 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);
+}
diff --git a/src/test/run-pass/macros/macro-at-most-once-rep.rs b/src/test/run-pass/macros/macro-at-most-once-rep.rs
deleted file mode 100644 (file)
index 582ef08..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-// 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);
-}
index e5b1cd93614bb572cd586c255f2969302aa9d4bc..a8e31a648c9ed4e67a41319d43afeecdc75b17fb 100644 (file)
@@ -1,7 +1,7 @@
 #![allow(unused_macros)]
 
 macro_rules! assign {
-    (($($a:tt)*) = ($($b:tt))*) => { //~ ERROR expected `*` or `+`
+    (($($a:tt)*) = ($($b:tt))*) => { //~ ERROR expected one of: `*`, `+`, or `?`
         $($a)* = $($b)*
     }
 }
index e04e16e2a037562a11f194214b2aa9aa328c96b0..62e7dff547692ead4c1aab1a46b6eb54a92d7aff 100644 (file)
@@ -1,4 +1,4 @@
-error: expected `*` or `+`
+error: expected one of: `*`, `+`, or `?`
   --> $DIR/issue-39388.rs:4:22
    |
 LL |     (($($a:tt)*) = ($($b:tt))*) => {
diff --git a/src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.rs b/src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.rs
deleted file mode 100644 (file)
index 2d8d2ec..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// 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() {}
diff --git a/src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.stderr b/src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.stderr
deleted file mode 100644 (file)
index e78f283..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-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
-
diff --git a/src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.rs b/src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.rs
deleted file mode 100644 (file)
index c8c920f..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-// 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);
-}
diff --git a/src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.stderr b/src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.stderr
deleted file mode 100644 (file)
index bf1861a..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-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>
-
diff --git a/src/test/ui/macros/macro-at-most-once-rep-2015.rs b/src/test/ui/macros/macro-at-most-once-rep-2015.rs
new file mode 100644 (file)
index 0000000..e6def0f
--- /dev/null
@@ -0,0 +1,41 @@
+// 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!(*);
+}
diff --git a/src/test/ui/macros/macro-at-most-once-rep-2015.stderr b/src/test/ui/macros/macro-at-most-once-rep-2015.stderr
new file mode 100644 (file)
index 0000000..81de4f1
--- /dev/null
@@ -0,0 +1,107 @@
+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
+
index 83f8a562a03ad4a2ae5b206c1672fb1155de8d58..9ed53519ceb3156a82eb00d9ddb3454e4f7688e2 100644 (file)
@@ -1,7 +1,7 @@
 macro_rules! foo {
     { $+ } => { //~ ERROR expected identifier, found `+`
                 //~^ ERROR missing fragment specifier
-        $(x)(y) //~ ERROR expected `*` or `+`
+        $(x)(y) //~ ERROR expected one of: `*`, `+`, or `?`
     }
 }
 
index 8ba72fc88862a77a54c207f28984977de3588b18..b4d38d3ce4806ca8c5a6d9bf50241a3c01bdb684 100644 (file)
@@ -4,7 +4,7 @@ error: expected identifier, found `+`
 LL |     { $+ } => {
    |        ^
 
-error: expected `*` or `+`
+error: expected one of: `*`, `+`, or `?`
   --> $DIR/issue-33569.rs:4:13
    |
 LL |         $(x)(y)