about summary refs log tree commit diff
path: root/src/test/ui/pattern
diff options
context:
space:
mode:
authormark <markm@cs.wisc.edu>2020-11-10 18:00:53 -0600
committermark <markm@cs.wisc.edu>2020-12-19 07:13:36 -0600
commit1a7d00a529503ac38a6b1ae28e8e779e434e02e0 (patch)
tree322ac3ba9ec48dc477bb84fea01b6ee0f74f5bf4 /src/test/ui/pattern
parente461b8137f8f7277147e3ec8ec0b7f0f31d32d0b (diff)
downloadrust-1a7d00a529503ac38a6b1ae28e8e779e434e02e0.tar.gz
rust-1a7d00a529503ac38a6b1ae28e8e779e434e02e0.zip
implement edition-specific :pat behavior for 2015/18
Diffstat (limited to 'src/test/ui/pattern')
-rw-r--r--src/test/ui/pattern/or-pattern-macro-pat.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/ui/pattern/or-pattern-macro-pat.rs b/src/test/ui/pattern/or-pattern-macro-pat.rs
new file mode 100644
index 00000000000..8749407675b
--- /dev/null
+++ b/src/test/ui/pattern/or-pattern-macro-pat.rs
@@ -0,0 +1,44 @@
+// run-pass
+// edition:2021
+// ignore-test
+// FIXME(mark-i-m): enable this test again when 2021 machinery is available
+
+#![feature(or_patterns)]
+
+use Foo::*;
+
+#[derive(Eq, PartialEq, Debug)]
+enum Foo {
+    A(u64),
+    B(u64),
+    C,
+    D,
+}
+
+macro_rules! foo {
+    ($orpat:pat, $val:expr) => {
+        match $val {
+            x @ ($orpat) => x, // leading vert would not be allowed in $orpat
+            _ => B(0xDEADBEEFu64),
+        }
+    };
+}
+
+macro_rules! bar {
+    ($orpat:pat, $val:expr) => {
+        match $val {
+            $orpat => 42, // leading vert allowed here
+            _ => 0xDEADBEEFu64,
+        }
+    };
+}
+
+fn main() {
+    // Test or-pattern.
+    let y = foo!(A(_)|B(_), A(32));
+    assert_eq!(y, A(32));
+
+    // Leading vert in or-pattern.
+    let y = bar!(|C| D, C);
+    assert_eq!(y, 42u64);
+}