about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorSimonas Kazlauskas <github@kazlauskas.me>2016-01-11 21:17:52 +0200
committerSimonas Kazlauskas <github@kazlauskas.me>2016-01-11 21:17:52 +0200
commit6d6e831c3398d99ffcaba3af4335e411535c68bb (patch)
treef48e6f70a07860958298b58c393a742e39434550 /src/test
parent6cc2e371359349e93c159e75298adbff7f8cef01 (diff)
parenta2960bc7c6108f92a6c8c27418b20af1337208cf (diff)
downloadrust-6d6e831c3398d99ffcaba3af4335e411535c68bb.tar.gz
rust-6d6e831c3398d99ffcaba3af4335e411535c68bb.zip
Rollup merge of #30694 - pnkfelix:issue-25658-real-first-follow, r=nrc
Proper first and follow sets for macro_rules future proofing

implements first stage of RFC amendment 1384; see #30450
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/issue-30715.rs7
-rw-r--r--src/test/compile-fail/macro-input-future-proofing.rs3
-rw-r--r--src/test/compile-fail/macro-seq-followed-by-seq.rs18
-rw-r--r--src/test/run-pass/macro-pat-follow.rs10
-rw-r--r--src/test/run-pass/macro-seq-followed-by-seq.rs26
5 files changed, 44 insertions, 20 deletions
diff --git a/src/test/compile-fail/issue-30715.rs b/src/test/compile-fail/issue-30715.rs
index 16761905cb9..7ad43954010 100644
--- a/src/test/compile-fail/issue-30715.rs
+++ b/src/test/compile-fail/issue-30715.rs
@@ -10,7 +10,12 @@
 
 macro_rules! parallel {
     (
-        for $id:ident in $iter:expr {
+        // If future has `pred`/`moelarry` fragments (where "pred" is
+        // "like expr, but with `{` in its FOLLOW set"), then could
+        // use `pred` instead of future-proof erroring here. See also:
+        //
+        // https://github.com/rust-lang/rfcs/pull/1384#issuecomment-160165525
+        for $id:ident in $iter:expr { //~ WARN `$iter:expr` is followed by `{`
             $( $inner:expr; )*
         }
     ) => {};
diff --git a/src/test/compile-fail/macro-input-future-proofing.rs b/src/test/compile-fail/macro-input-future-proofing.rs
index 15f6d88fd89..fe758a4a631 100644
--- a/src/test/compile-fail/macro-input-future-proofing.rs
+++ b/src/test/compile-fail/macro-input-future-proofing.rs
@@ -18,13 +18,14 @@ macro_rules! errors_everywhere {
     ($bl:block < ) => ();
     ($pa:pat >) => (); //~ ERROR `$pa:pat` is followed by `>`, which is not allowed for `pat`
     ($pa:pat , ) => ();
-    ($pa:pat | ) => (); //~ ERROR `$pa:pat` is followed by `|`
     ($pa:pat $pb:pat $ty:ty ,) => ();
     //~^ ERROR `$pa:pat` is followed by `$pb:pat`, which is not allowed
     //~^^ ERROR `$pb:pat` is followed by `$ty:ty`, which is not allowed
     ($($ty:ty)* -) => (); //~ ERROR `$ty:ty` is followed by `-`
     ($($a:ty, $b:ty)* -) => (); //~ ERROR `$b:ty` is followed by `-`
     ($($ty:ty)-+) => (); //~ ERROR `$ty:ty` is followed by `-`, which is not allowed for `ty`
+    ( $($a:expr)* $($b:tt)* ) => { };
+    //~^ ERROR `$a:expr` is followed by `$b:tt`, which is not allowed for `expr` fragments
 }
 
 fn main() { }
diff --git a/src/test/compile-fail/macro-seq-followed-by-seq.rs b/src/test/compile-fail/macro-seq-followed-by-seq.rs
deleted file mode 100644
index b4f71343d54..00000000000
--- a/src/test/compile-fail/macro-seq-followed-by-seq.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Check that we cannot have two sequence repetitions in a row.
-
-macro_rules! foo {
-  ( $($a:expr)* $($b:tt)* ) => { }; //~ ERROR sequence repetition followed by another sequence
-  ( $($a:tt)* $($b:tt)* ) => { }; //~ ERROR sequence repetition followed by another sequence
-}
-
-fn main() { }
diff --git a/src/test/run-pass/macro-pat-follow.rs b/src/test/run-pass/macro-pat-follow.rs
index 77c6ed4447f..c1abebd5f90 100644
--- a/src/test/run-pass/macro-pat-follow.rs
+++ b/src/test/run-pass/macro-pat-follow.rs
@@ -24,7 +24,17 @@ macro_rules! pat_if {
     }}
 }
 
+macro_rules! pat_bar {
+    ($p:pat | $p2:pat) => {{
+        match Some(1u8) {
+            $p | $p2 => {},
+            _ => {}
+        }
+    }}
+}
+
 fn main() {
     pat_in!(Some(_) in 0..10);
     pat_if!(Some(x) if x > 0);
+    pat_bar!(Some(1u8) | None);
 }
diff --git a/src/test/run-pass/macro-seq-followed-by-seq.rs b/src/test/run-pass/macro-seq-followed-by-seq.rs
new file mode 100644
index 00000000000..23c7d2516a2
--- /dev/null
+++ b/src/test/run-pass/macro-seq-followed-by-seq.rs
@@ -0,0 +1,26 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test of allowing two sequences repetitions in a row,
+// functionality added as byproduct of RFC amendment #1384
+//   https://github.com/rust-lang/rfcs/pull/1384
+
+// Old version of Rust would reject this macro definition, even though
+// there are no local ambiguities (the initial `banana` and `orange`
+// tokens are enough for the expander to distinguish which case is
+// intended).
+macro_rules! foo {
+    ( $(banana $a:ident)* $(orange $b:tt)* ) => { };
+}
+
+fn main() {
+    foo!( banana id1 banana id2
+          orange hi  orange (hello world) );
+}