]> git.lizzy.rs Git - rust.git/commitdiff
Make exhaustiveness error message more consistent for slice patterns
authorNadrieril <nadrieril+git@gmail.com>
Sun, 3 Nov 2019 23:11:04 +0000 (23:11 +0000)
committerNadrieril <nadrieril+git@gmail.com>
Tue, 5 Nov 2019 17:59:01 +0000 (17:59 +0000)
This improves error messages by indicating when slices above a certain
lengths have not been matched. Previously, we would only report examples
of such lengths, but of course never all of them.

src/librustc_mir/hair/pattern/_match.rs
src/test/ui/consts/const_let_refutable.stderr
src/test/ui/pattern/usefulness/match-byte-array-patterns-2.stderr
src/test/ui/pattern/usefulness/non-exhaustive-match.rs
src/test/ui/pattern/usefulness/non-exhaustive-match.stderr
src/test/ui/pattern/usefulness/slice-patterns.rs
src/test/ui/pattern/usefulness/slice-patterns.stderr
src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr

index 902d9b610ce3339be63f650403518cf8f099de1a..c70a7ea1f37dda2e2260844306ccb450a372684b 100644 (file)
@@ -841,9 +841,17 @@ fn apply<'a>(
 
             ty::Ref(..) => PatKind::Deref { subpattern: subpatterns.nth(0).unwrap() },
 
-            ty::Slice(_) | ty::Array(..) => {
-                PatKind::Slice { prefix: subpatterns.collect(), slice: None, suffix: vec![] }
-            }
+            ty::Slice(_) | ty::Array(..) => match self {
+                FixedLenSlice(_) => {
+                    PatKind::Slice { prefix: subpatterns.collect(), slice: None, suffix: vec![] }
+                }
+                VarLenSlice(_) => {
+                    let prefix = subpatterns.collect();
+                    let wild = Pat { ty, span: DUMMY_SP, kind: Box::new(PatKind::Wild) };
+                    PatKind::Slice { prefix, slice: Some(wild), suffix: vec![] }
+                }
+                _ => bug!("bad slice pattern {:?} {:?}", self, ty),
+            },
 
             _ => match *self {
                 ConstantValue(value, _) => PatKind::Constant { value },
index 7f15f02d4d37bb3e96a382d16c8b45f6dddb3335..9acb4ad9cbbe5e4c3f8c4616de1b5546c5f8c11b 100644 (file)
@@ -1,8 +1,8 @@
-error[E0005]: refutable pattern in function argument: `&[]`, `&[_]` and `&[_, _, _]` not covered
+error[E0005]: refutable pattern in function argument: `&[]`, `&[_]` and `&[_, _, _, ..]` not covered
   --> $DIR/const_let_refutable.rs:3:16
    |
 LL | const fn slice([a, b]: &[i32]) -> i32 {
-   |                ^^^^^^ patterns `&[]`, `&[_]` and `&[_, _, _]` not covered
+   |                ^^^^^^ patterns `&[]`, `&[_]` and `&[_, _, _, ..]` not covered
 
 error[E0723]: can only call other `const fn` within a `const fn`, but `const <&i32 as std::ops::Add>::add` is not stable as `const fn`
   --> $DIR/const_let_refutable.rs:4:5
index 9938c9c284d1c8e584e0f3ada6ecca3dcb0e4ff8..6e52072e3bfec7f91f6ec8f34307b0c09d289b08 100644 (file)
@@ -6,11 +6,11 @@ LL |     match buf {
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
-error[E0004]: non-exhaustive patterns: `&[]` not covered
+error[E0004]: non-exhaustive patterns: `&[..]` not covered
   --> $DIR/match-byte-array-patterns-2.rs:10:11
    |
 LL |     match buf {
-   |           ^^^ pattern `&[]` not covered
+   |           ^^^ pattern `&[..]` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
index 0e5a9203c5f80ac5f532dc8d61a6f4882c2791ce..bfca5352353a7c0c6ad724bc0bb3e8d438f5a391 100644 (file)
@@ -44,7 +44,7 @@ fn main() {
     }
     let vec = vec![0.5f32];
     let vec: &[f32] = &vec;
-    match *vec { //~ ERROR non-exhaustive patterns: `[_, _, _, _]` not covered
+    match *vec { //~ ERROR non-exhaustive patterns: `[_, _, _, _, ..]` not covered
         [0.1, 0.2, 0.3] => (),
         [0.1, 0.2] => (),
         [0.1] => (),
index 5dba05e16427a8df24a27d5308bbe316b5d2c2c3..577867e4e712294025aaff2a88e562aa05f35538 100644 (file)
@@ -66,11 +66,11 @@ LL |     match *vec {
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
-error[E0004]: non-exhaustive patterns: `[_, _, _, _]` not covered
+error[E0004]: non-exhaustive patterns: `[_, _, _, _, ..]` not covered
   --> $DIR/non-exhaustive-match.rs:47:11
    |
 LL |     match *vec {
-   |           ^^^^ pattern `[_, _, _, _]` not covered
+   |           ^^^^ pattern `[_, _, _, _, ..]` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
index 0493646ff3bba69099d0c7116c1e0fd22b5c094a..97086c4d75ddc87c6d15b62e4498bc4cc4eb75dc 100644 (file)
@@ -48,11 +48,11 @@ fn main() {
         [true, .., true] => {}
     }
     match s {
-    //~^ ERROR `&[_]` not covered
+    //~^ ERROR `&[_, ..]` not covered
         [] => {}
     }
     match s {
-    //~^ ERROR `&[_, _]` not covered
+    //~^ ERROR `&[_, _, ..]` not covered
         [] => {}
         [_] => {}
     }
index 18c73330fcdc14eb2a985b3fa8184c531c8d9c62..3cea068543ebdf7fd6ecf800989e990a23cfbfa4 100644 (file)
@@ -30,19 +30,19 @@ LL |     match s3 {
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
-error[E0004]: non-exhaustive patterns: `&[_]` not covered
+error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered
   --> $DIR/slice-patterns.rs:50:11
    |
 LL |     match s {
-   |           ^ pattern `&[_]` not covered
+   |           ^ pattern `&[_, ..]` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
-error[E0004]: non-exhaustive patterns: `&[_, _]` not covered
+error[E0004]: non-exhaustive patterns: `&[_, _, ..]` not covered
   --> $DIR/slice-patterns.rs:54:11
    |
 LL |     match s {
-   |           ^ pattern `&[_, _]` not covered
+   |           ^ pattern `&[_, _, ..]` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
index a49344e45cec652775d6737f3b8c178d9477e0fa..7af6075262c6db9e75b3ec2ea39ef04d0ac86022 100644 (file)
@@ -30,11 +30,11 @@ LL |     let _ = match x {};
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
-error[E0004]: non-exhaustive patterns: `&[_]` not covered
+error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered
   --> $DIR/uninhabited-matches-feature-gated.rs:21:19
    |
 LL |     let _ = match x {
-   |                   ^ pattern `&[_]` not covered
+   |                   ^ pattern `&[_, ..]` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms