about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-07-29 09:03:27 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-07-29 21:04:03 +0200
commit15bc63e8bfd575c709a45f7c6845acfe0f3fdc92 (patch)
treefccb30c5e4db8673c51a97d9f918bb894124f471
parent8b94e9e9188b65df38a5f1ae723617dc2dfb3155 (diff)
downloadrust-15bc63e8bfd575c709a45f7c6845acfe0f3fdc92.tar.gz
rust-15bc63e8bfd575c709a45f7c6845acfe0f3fdc92.zip
Add syntactic test for rest patterns.
-rw-r--r--src/test/ui/pattern/rest-pat-syntactic.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/test/ui/pattern/rest-pat-syntactic.rs b/src/test/ui/pattern/rest-pat-syntactic.rs
new file mode 100644
index 00000000000..9656a0b5de9
--- /dev/null
+++ b/src/test/ui/pattern/rest-pat-syntactic.rs
@@ -0,0 +1,70 @@
+// Here we test that `..` is allowed in all pattern locations *syntactically*.
+// The semantic test is in `rest-pat-semantic-disallowed.rs`.
+
+// check-pass
+
+fn main() {}
+
+macro_rules! accept_pat {
+    ($p:pat) => {}
+}
+
+accept_pat!(..);
+
+#[cfg(FALSE)]
+fn rest_patterns() {
+    // Top level:
+    fn foo(..: u8) {}
+    let ..;
+
+    // Box patterns:
+    let box ..;
+
+    // In or-patterns:
+    match x {
+        .. | .. => {}
+    }
+
+    // Ref patterns:
+    let &..;
+    let &mut ..;
+
+    // Ident patterns:
+    let x @ ..;
+    let ref x @ ..;
+    let ref mut x @ ..;
+
+    // Tuple:
+    let (..); // This is interpreted as a tuple pattern, not a parenthesis one.
+    let (..,); // Allowing trailing comma.
+    let (.., .., ..); // Duplicates also.
+    let (.., P, ..); // Including with things in between.
+
+    // Tuple struct (same idea as for tuple patterns):
+    let A(..);
+    let A(..,);
+    let A(.., .., ..);
+    let A(.., P, ..);
+
+    // Array/Slice (like with tuple patterns):
+    let [..];
+    let [..,];
+    let [.., .., ..];
+    let [.., P, ..];
+
+    // Random walk to guard against special casing:
+    match x {
+        .. |
+        [
+            (
+                box ..,
+                &(..),
+                &mut ..,
+                x @ ..
+            ),
+            ref x @ ..,
+        ] |
+        ref mut x @ ..
+        => {}
+    }
+}