about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/destructuring-assignment/slice_destructure_fail.rs2
-rw-r--r--tests/ui/destructuring-assignment/slice_destructure_fail.stderr25
-rw-r--r--tests/ui/pattern/issue-76342.rs25
-rw-r--r--tests/ui/pattern/slice-array-infer.rs27
-rw-r--r--tests/ui/pattern/slice-patterns-irrefutable.rs62
-rw-r--r--tests/ui/pattern/slice-patterns-irrefutable.stderr14
6 files changed, 106 insertions, 49 deletions
diff --git a/tests/ui/destructuring-assignment/slice_destructure_fail.rs b/tests/ui/destructuring-assignment/slice_destructure_fail.rs
index e36557940ee..e5bb50030b9 100644
--- a/tests/ui/destructuring-assignment/slice_destructure_fail.rs
+++ b/tests/ui/destructuring-assignment/slice_destructure_fail.rs
@@ -3,8 +3,6 @@ fn main() {
     [a, .., b, ..] = [0, 1]; //~ ERROR `..` can only be used once per slice pattern
     [a, a, b] = [1, 2];
     //~^ ERROR pattern requires 3 elements but array has 2
-    //~| ERROR mismatched types
     [_] = [1, 2];
     //~^ ERROR pattern requires 1 element but array has 2
-    //~| ERROR mismatched types
 }
diff --git a/tests/ui/destructuring-assignment/slice_destructure_fail.stderr b/tests/ui/destructuring-assignment/slice_destructure_fail.stderr
index e42b9695d4d..acf44ceb184 100644
--- a/tests/ui/destructuring-assignment/slice_destructure_fail.stderr
+++ b/tests/ui/destructuring-assignment/slice_destructure_fail.stderr
@@ -6,37 +6,18 @@ LL |     [a, .., b, ..] = [0, 1];
    |         |
    |         previously used here
 
-error[E0308]: mismatched types
-  --> $DIR/slice_destructure_fail.rs:4:5
-   |
-LL |     [a, a, b] = [1, 2];
-   |     ^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements
-   |
-   = note: expected array `[{integer}; 2]`
-              found array `[_; 3]`
-
 error[E0527]: pattern requires 3 elements but array has 2
   --> $DIR/slice_destructure_fail.rs:4:5
    |
 LL |     [a, a, b] = [1, 2];
    |     ^^^^^^^^^ expected 2 elements
 
-error[E0308]: mismatched types
-  --> $DIR/slice_destructure_fail.rs:7:5
-   |
-LL |     [_] = [1, 2];
-   |     ^^^ expected an array with a fixed size of 2 elements, found one with 1 element
-   |
-   = note: expected array `[{integer}; 2]`
-              found array `[_; 1]`
-
 error[E0527]: pattern requires 1 element but array has 2
-  --> $DIR/slice_destructure_fail.rs:7:5
+  --> $DIR/slice_destructure_fail.rs:6:5
    |
 LL |     [_] = [1, 2];
    |     ^^^ expected 2 elements
 
-error: aborting due to 5 previous errors
+error: aborting due to 3 previous errors
 
-Some errors have detailed explanations: E0308, E0527.
-For more information about an error, try `rustc --explain E0308`.
+For more information about this error, try `rustc --explain E0527`.
diff --git a/tests/ui/pattern/issue-76342.rs b/tests/ui/pattern/issue-76342.rs
deleted file mode 100644
index e4d3218104e..00000000000
--- a/tests/ui/pattern/issue-76342.rs
+++ /dev/null
@@ -1,25 +0,0 @@
-// check-pass
-
-// Test that we infer the expected type of a pattern to an array of the given length.
-
-#![allow(unused_variables)]
-struct Zeroes;
-impl Into<[usize; 2]> for Zeroes {
-    fn into(self) -> [usize; 2] {
-        [0; 2]
-    }
-}
-impl Into<[usize; 3]> for Zeroes {
-    fn into(self) -> [usize; 3] {
-        [0; 3]
-    }
-}
-impl Into<[usize; 4]> for Zeroes {
-    fn into(self) -> [usize; 4] {
-        [0; 4]
-    }
-}
-fn main() {
-    let [a, b, c] = Zeroes.into();
-    let [d, e, f]: [_; 3] = Zeroes.into();
-}
diff --git a/tests/ui/pattern/slice-array-infer.rs b/tests/ui/pattern/slice-array-infer.rs
new file mode 100644
index 00000000000..f94a3dcfe0a
--- /dev/null
+++ b/tests/ui/pattern/slice-array-infer.rs
@@ -0,0 +1,27 @@
+// check-pass
+
+#![allow(unused_variables)]
+#![feature(generic_arg_infer)]
+
+struct Zeroes;
+impl Into<&'static [usize; 3]> for Zeroes {
+    fn into(self) -> &'static [usize; 3] {
+        &[0; 3]
+    }
+}
+impl Into<[usize; 3]> for Zeroes {
+    fn into(self) -> [usize; 3] {
+        [0; 3]
+    }
+}
+fn main() {
+    let [a, b, c] = Zeroes.into();
+    let [d, e, f] = <Zeroes as Into<&'static [usize; 3]>>::into(Zeroes);
+    let &[g, h, i] = Zeroes.into();
+    let [j, k, l]: [usize; _] = Zeroes.into();
+    let [m, n, o]: &[usize; _] = Zeroes.into();
+
+    // check the binding mode of these patterns:
+    let _: &[usize] = &[a, b, c, g, h, i, j, k, l];
+    let _: &[&usize] = &[d, e, f, m, n, o];
+}
diff --git a/tests/ui/pattern/slice-patterns-irrefutable.rs b/tests/ui/pattern/slice-patterns-irrefutable.rs
new file mode 100644
index 00000000000..7be02b44e43
--- /dev/null
+++ b/tests/ui/pattern/slice-patterns-irrefutable.rs
@@ -0,0 +1,62 @@
+// Test that we infer the expected type of a pattern to an array of the given length.
+
+#![allow(unused_variables)]
+
+use std::array::TryFromSliceError;
+use std::convert::TryInto;
+
+struct Zeroes;
+impl Into<[usize; 2]> for Zeroes {
+    fn into(self) -> [usize; 2] {
+        [0; 2]
+    }
+}
+impl Into<[usize; 3]> for Zeroes {
+    fn into(self) -> [usize; 3] {
+        [0; 3]
+    }
+}
+impl Into<[usize; 4]> for Zeroes {
+    fn into(self) -> [usize; 4] {
+        [0; 4]
+    }
+}
+
+fn zeroes_into() {
+    let [a, b, c] = Zeroes.into();
+    let [d, e, f]: [_; 3] = Zeroes.into();
+}
+
+fn array_try_from(x: &[usize]) -> Result<usize, TryFromSliceError> {
+    let [a, b] = x.try_into()?;
+    Ok(a + b)
+}
+
+fn default() {
+    let a: i32;
+    let b;
+    [a, b] = Default::default();
+}
+
+fn test_nested_array() {
+    let a: [_; 3];
+    let b;
+    //~^ ERROR type annotations needed
+    [a, b] = Default::default();
+}
+
+struct Foo<T>([T; 2]);
+
+impl<T: Default + Copy> Default for Foo<T> {
+    fn default() -> Self {
+        Foo([Default::default(); 2])
+    }
+}
+
+fn field_array() {
+    let a: i32;
+    let b;
+    Foo([a, b]) = Default::default();
+}
+
+fn main() {}
diff --git a/tests/ui/pattern/slice-patterns-irrefutable.stderr b/tests/ui/pattern/slice-patterns-irrefutable.stderr
new file mode 100644
index 00000000000..fac99534f3e
--- /dev/null
+++ b/tests/ui/pattern/slice-patterns-irrefutable.stderr
@@ -0,0 +1,14 @@
+error[E0282]: type annotations needed for `[_; 3]`
+  --> $DIR/slice-patterns-irrefutable.rs:43:9
+   |
+LL |     let b;
+   |         ^
+   |
+help: consider giving `b` an explicit type, where the placeholders `_` are specified
+   |
+LL |     let b: [_; 3];
+   |          ++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.