about summary refs log tree commit diff
path: root/tests/ui/pattern/bindings-after-at/slice-patterns.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/pattern/bindings-after-at/slice-patterns.rs')
-rw-r--r--tests/ui/pattern/bindings-after-at/slice-patterns.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/pattern/bindings-after-at/slice-patterns.rs b/tests/ui/pattern/bindings-after-at/slice-patterns.rs
new file mode 100644
index 00000000000..4f4c96e450b
--- /dev/null
+++ b/tests/ui/pattern/bindings-after-at/slice-patterns.rs
@@ -0,0 +1,39 @@
+// Test bindings-after-at with slice-patterns
+
+// run-pass
+
+
+#[derive(Debug, PartialEq)]
+enum MatchArm {
+    Arm(usize),
+    Wild,
+}
+
+fn test(foo: &[i32]) -> MatchArm {
+    match foo {
+        [bar @ .., n] if n == &5 => {
+            for i in bar {
+                assert!(i < &5);
+            }
+
+            MatchArm::Arm(0)
+        },
+        bar @ [x0, .., xn] => {
+            assert_eq!(x0, &1);
+            assert_eq!(x0, &1);
+            assert_eq!(xn, &4);
+            assert_eq!(bar, &[1, 2, 3, 4]);
+
+            MatchArm::Arm(1)
+        },
+        _ => MatchArm::Wild,
+    }
+}
+
+fn main() {
+    let foo = vec![1, 2, 3, 4, 5];
+
+    assert_eq!(test(&foo), MatchArm::Arm(0));
+    assert_eq!(test(&foo[..4]), MatchArm::Arm(1));
+    assert_eq!(test(&foo[0..1]), MatchArm::Wild);
+}