about summary refs log tree commit diff
path: root/src/test/ui/array-slice-vec
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-30 01:37:14 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-01-18 19:33:47 +0100
commite3c2f8fc57e718f4ba1d7f52405eb2c1cb434559 (patch)
treec21ecdb50427d23fe5819603035b75a03396a213 /src/test/ui/array-slice-vec
parenta1eadca88f03de91f5eecd316419d32e2a302c2b (diff)
downloadrust-e3c2f8fc57e718f4ba1d7f52405eb2c1cb434559.tar.gz
rust-e3c2f8fc57e718f4ba1d7f52405eb2c1cb434559.zip
slice_patterns: organize some tests
Diffstat (limited to 'src/test/ui/array-slice-vec')
-rw-r--r--src/test/ui/array-slice-vec/slice-pat-type-mismatches.rs36
-rw-r--r--src/test/ui/array-slice-vec/slice-pat-type-mismatches.stderr36
-rw-r--r--src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.rs11
-rw-r--r--src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.stderr24
4 files changed, 107 insertions, 0 deletions
diff --git a/src/test/ui/array-slice-vec/slice-pat-type-mismatches.rs b/src/test/ui/array-slice-vec/slice-pat-type-mismatches.rs
new file mode 100644
index 00000000000..34adb42a32f
--- /dev/null
+++ b/src/test/ui/array-slice-vec/slice-pat-type-mismatches.rs
@@ -0,0 +1,36 @@
+fn main() {
+    match "foo".to_string() {
+        ['f', 'o', ..] => {}
+        //~^ ERROR expected an array or slice, found `std::string::String`
+        _ => { }
+    };
+
+    // Note that this one works with default binding modes.
+    match &[0, 1, 2] {
+        [..] => {}
+    };
+
+    match &[0, 1, 2] {
+        &[..] => {} // ok
+    };
+
+    match [0, 1, 2] {
+        [0] => {}, //~ ERROR pattern requires
+
+        [0, 1, x @ ..] => {
+            let a: [_; 1] = x;
+        }
+        [0, 1, 2, 3, x @ ..] => {} //~ ERROR pattern requires
+    };
+
+    match does_not_exist { //~ ERROR cannot find value `does_not_exist` in this scope
+        [] => {}
+    };
+}
+
+fn another_fn_to_avoid_suppression() {
+    match Default::default()
+    {
+        [] => {}  //~ ERROR type annotations needed
+    };
+}
diff --git a/src/test/ui/array-slice-vec/slice-pat-type-mismatches.stderr b/src/test/ui/array-slice-vec/slice-pat-type-mismatches.stderr
new file mode 100644
index 00000000000..c4548142c13
--- /dev/null
+++ b/src/test/ui/array-slice-vec/slice-pat-type-mismatches.stderr
@@ -0,0 +1,36 @@
+error[E0425]: cannot find value `does_not_exist` in this scope
+  --> $DIR/slice-pat-type-mismatches.rs:26:11
+   |
+LL |     match does_not_exist {
+   |           ^^^^^^^^^^^^^^ not found in this scope
+
+error[E0529]: expected an array or slice, found `std::string::String`
+  --> $DIR/slice-pat-type-mismatches.rs:3:9
+   |
+LL |         ['f', 'o', ..] => {}
+   |         ^^^^^^^^^^^^^^ pattern cannot match with input type `std::string::String`
+
+error[E0527]: pattern requires 1 element but array has 3
+  --> $DIR/slice-pat-type-mismatches.rs:18:9
+   |
+LL |         [0] => {},
+   |         ^^^ expected 3 elements
+
+error[E0528]: pattern requires at least 4 elements but array has 3
+  --> $DIR/slice-pat-type-mismatches.rs:23:9
+   |
+LL |         [0, 1, 2, 3, x @ ..] => {}
+   |         ^^^^^^^^^^^^^^^^^^^^ pattern cannot match array of 3 elements
+
+error[E0282]: type annotations needed
+  --> $DIR/slice-pat-type-mismatches.rs:34:9
+   |
+LL |         [] => {}
+   |         ^^ cannot infer type
+   |
+   = note: type must be known at this point
+
+error: aborting due to 5 previous errors
+
+Some errors have detailed explanations: E0282, E0425, E0527, E0528, E0529.
+For more information about an error, try `rustc --explain E0282`.
diff --git a/src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.rs b/src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.rs
new file mode 100644
index 00000000000..97e33624bf6
--- /dev/null
+++ b/src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.rs
@@ -0,0 +1,11 @@
+fn main() {
+    let a: &[u8] = &[];
+    match a {
+        [1, tail @ .., tail @ ..] => {},
+        //~^ ERROR identifier `tail` is bound more than once in the same pattern
+        //~| ERROR `..` can only be used once per slice pattern
+        _ => ()
+    }
+}
+
+const RECOVERY_WITNESS: () = 0; //~ ERROR mismatched types
diff --git a/src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.stderr b/src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.stderr
new file mode 100644
index 00000000000..4d6078788b2
--- /dev/null
+++ b/src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.stderr
@@ -0,0 +1,24 @@
+error[E0416]: identifier `tail` is bound more than once in the same pattern
+  --> $DIR/subslice-only-once-semantic-restriction.rs:4:24
+   |
+LL |         [1, tail @ .., tail @ ..] => {},
+   |                        ^^^^ used in a pattern more than once
+
+error: `..` can only be used once per slice pattern
+  --> $DIR/subslice-only-once-semantic-restriction.rs:4:31
+   |
+LL |         [1, tail @ .., tail @ ..] => {},
+   |                    --         ^^ can only be used once per slice pattern
+   |                    |
+   |                    previously used here
+
+error[E0308]: mismatched types
+  --> $DIR/subslice-only-once-semantic-restriction.rs:11:30
+   |
+LL | const RECOVERY_WITNESS: () = 0;
+   |                              ^ expected `()`, found integer
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0308, E0416.
+For more information about an error, try `rustc --explain E0308`.