]> git.lizzy.rs Git - rust.git/commitdiff
update tests, improve variable names
authorBastian Kauschke <bastian_kauschke@hotmail.de>
Mon, 30 Mar 2020 17:34:16 +0000 (19:34 +0200)
committerBastian Kauschke <bastian_kauschke@hotmail.de>
Mon, 30 Mar 2020 17:34:16 +0000 (19:34 +0200)
src/librustc_error_codes/error_codes/E0730.md
src/librustc_typeck/check/pat.rs
src/test/ui/array-slice-vec/match_arr_unknown_len.rs [new file with mode: 0644]
src/test/ui/array-slice-vec/match_arr_unknown_len.stderr [new file with mode: 0644]
src/test/ui/error-codes/E0730.rs
src/test/ui/error-codes/E0730.stderr

index bf1f72be3258926bd7f107935517027cbda26f8a..c2a71ca5669a130b62c96eb4dd17e59d8e06acf3 100644 (file)
@@ -7,8 +7,8 @@ Example of erroneous code:
 
 fn is_123<const N: usize>(x: [u32; N]) -> bool {
     match x {
-        [1, 2, 3] => true, // error: cannot pattern-match on an
-                           //        array without a fixed length
+        [1, 2, ..] => true, // error: cannot pattern-match on an
+                            //        array without a fixed length
         _ => false
     }
 }
index 9dbf0489470f7e7791db3a2d738b64e2b5b72d82..b3cace8298a923852fc9198b3285cbecd3e175a1 100644 (file)
@@ -1355,7 +1355,7 @@ fn check_pat_slice(
     ) -> Ty<'tcx> {
         let err = self.tcx.types.err;
         let expected = self.structurally_resolved_type(span, expected);
-        let (element_ty, slice_ty, expected) = match expected.kind {
+        let (element_ty, slice_ty, inferred) = match expected.kind {
             // An array, so we might have something like `let [a, b, c] = [0, 1, 2];`.
             ty::Array(element_ty, len) => {
                 let min = before.len() as u64 + after.len() as u64;
@@ -1385,7 +1385,7 @@ fn check_pat_slice(
         for elt in after {
             self.check_pat(&elt, element_ty, def_bm, ti);
         }
-        expected
+        inferred
     }
 
     /// Type check the length of an array pattern.
diff --git a/src/test/ui/array-slice-vec/match_arr_unknown_len.rs b/src/test/ui/array-slice-vec/match_arr_unknown_len.rs
new file mode 100644 (file)
index 0000000..7f3da75
--- /dev/null
@@ -0,0 +1,11 @@
+#![feature(const_generics)]
+//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
+
+fn is_123<const N: usize>(x: [u32; N]) -> bool {
+    match x {
+        [1, 2] => true, //~ ERROR mismatched types
+        _ => false
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/array-slice-vec/match_arr_unknown_len.stderr b/src/test/ui/array-slice-vec/match_arr_unknown_len.stderr
new file mode 100644 (file)
index 0000000..9edb139
--- /dev/null
@@ -0,0 +1,20 @@
+warning: the feature `const_generics` is incomplete and may cause the compiler to crash
+  --> $DIR/match_arr_unknown_len.rs:1:12
+   |
+LL | #![feature(const_generics)]
+   |            ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(incomplete_features)]` on by default
+
+error[E0308]: mismatched types
+  --> $DIR/match_arr_unknown_len.rs:6:9
+   |
+LL |         [1, 2] => true,
+   |         ^^^^^^ expected `2usize`, found `N`
+   |
+   = note: expected array `[u32; 2]`
+              found array `[u32; _]`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
index 45fc7e13d17820fbb7256546c82a226824e9654e..66a6e1c817a37afe2a5108e4866f40dc9cf59a85 100644 (file)
@@ -3,7 +3,7 @@
 
 fn is_123<const N: usize>(x: [u32; N]) -> bool {
     match x {
-        [1, 2, 3] => true, //~ ERROR mismatched types
+        [1, 2, ..] => true, //~ ERROR cannot pattern-match on an array without a fixed length
         _ => false
     }
 }
index 834a3e9687059c57661922094333edbeeebfa329..fb53ae31c0b428a0bf9b9335db2ab84266937afd 100644 (file)
@@ -6,15 +6,12 @@ LL | #![feature(const_generics)]
    |
    = note: `#[warn(incomplete_features)]` on by default
 
-error[E0308]: mismatched types
+error[E0730]: cannot pattern-match on an array without a fixed length
   --> $DIR/E0730.rs:6:9
    |
-LL |         [1, 2, 3] => true,
-   |         ^^^^^^^^^ expected `3usize`, found `N`
-   |
-   = note: expected array `[u32; 3]`
-              found array `[u32; _]`
+LL |         [1, 2, ..] => true,
+   |         ^^^^^^^^^^
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0308`.
+For more information about this error, try `rustc --explain E0730`.