about summary refs log tree commit diff
path: root/src/test/ui/pattern
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-09-26 06:44:28 +0000
committerbors <bors@rust-lang.org>2020-09-26 06:44:28 +0000
commitfd15e6180d9c48b4f1157e44cdaff6e901e5f854 (patch)
tree11801a40b3c4b0ccc7c10b589347b28348705871 /src/test/ui/pattern
parent9e1c4361780e69ed54444a3b03fef0cbbc26b547 (diff)
parentdaf976f6129e5fb16effc48bf91853548774e235 (diff)
downloadrust-fd15e6180d9c48b4f1157e44cdaff6e901e5f854.tar.gz
rust-fd15e6180d9c48b4f1157e44cdaff6e901e5f854.zip
Auto merge of #70743 - oli-obk:eager_const_to_pat_conversion, r=eddyb
Fully destructure constants into patterns

r? `@varkor`

as discussed in https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/constants.20in.20patterns/near/192789924

we should probably crater it once reviewed
Diffstat (limited to 'src/test/ui/pattern')
-rw-r--r--src/test/ui/pattern/const-pat-ice.rs8
-rw-r--r--src/test/ui/pattern/const-pat-ice.stderr13
-rw-r--r--src/test/ui/pattern/issue-71042-opaquely-typed-constant-used-in-pattern.rs3
-rw-r--r--src/test/ui/pattern/issue-71042-opaquely-typed-constant-used-in-pattern.stderr4
-rw-r--r--src/test/ui/pattern/usefulness/exhaustive_integer_patterns.rs2
-rw-r--r--src/test/ui/pattern/usefulness/exhaustive_integer_patterns.stderr8
-rw-r--r--src/test/ui/pattern/usefulness/slice-pattern-const-2.rs6
-rw-r--r--src/test/ui/pattern/usefulness/slice-pattern-const-2.stderr26
-rw-r--r--src/test/ui/pattern/usefulness/slice-pattern-const-3.rs6
-rw-r--r--src/test/ui/pattern/usefulness/slice-pattern-const-3.stderr26
-rw-r--r--src/test/ui/pattern/usefulness/slice-patterns-exhaustiveness.rs62
-rw-r--r--src/test/ui/pattern/usefulness/slice-patterns-exhaustiveness.stderr48
12 files changed, 148 insertions, 64 deletions
diff --git a/src/test/ui/pattern/const-pat-ice.rs b/src/test/ui/pattern/const-pat-ice.rs
index 06558767882..abfacf3936b 100644
--- a/src/test/ui/pattern/const-pat-ice.rs
+++ b/src/test/ui/pattern/const-pat-ice.rs
@@ -1,10 +1,4 @@
-// failure-status: 101
-// rustc-env:RUST_BACKTRACE=0
-// normalize-stderr-test "note: rustc 1.* running on .*" -> "note: rustc VERSION running on TARGET"
-// normalize-stderr-test "note: compiler flags: .*" -> "note: compiler flags: FLAGS"
-// normalize-stderr-test "/_match.rs:[0-9]+:[0-9]+" -> "/_match.rs:LL:CC"
-
-// This is a repro test for an ICE in our pattern handling of constants.
+// check-pass
 
 const FOO: &&&u32 = &&&42;
 
diff --git a/src/test/ui/pattern/const-pat-ice.stderr b/src/test/ui/pattern/const-pat-ice.stderr
deleted file mode 100644
index 6b42c0e0848..00000000000
--- a/src/test/ui/pattern/const-pat-ice.stderr
+++ /dev/null
@@ -1,13 +0,0 @@
-thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', compiler/rustc_mir_build/src/thir/pattern/_match.rs:LL:CC
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
-
-error: internal compiler error: unexpected panic
-
-note: the compiler unexpectedly panicked. this is a bug.
-
-note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
-
-note: rustc VERSION running on TARGET
-
-note: compiler flags: FLAGS
-
diff --git a/src/test/ui/pattern/issue-71042-opaquely-typed-constant-used-in-pattern.rs b/src/test/ui/pattern/issue-71042-opaquely-typed-constant-used-in-pattern.rs
index c5e4a72fb9f..65f27cf78f1 100644
--- a/src/test/ui/pattern/issue-71042-opaquely-typed-constant-used-in-pattern.rs
+++ b/src/test/ui/pattern/issue-71042-opaquely-typed-constant-used-in-pattern.rs
@@ -4,6 +4,7 @@
 fn main() {
     const C: impl Copy = 0;
     match C {
-        C | _ => {} //~ ERROR: opaque types cannot be used in patterns
+        C | //~ ERROR: `impl Copy` cannot be used in patterns
+        _ => {}
     }
 }
diff --git a/src/test/ui/pattern/issue-71042-opaquely-typed-constant-used-in-pattern.stderr b/src/test/ui/pattern/issue-71042-opaquely-typed-constant-used-in-pattern.stderr
index 7695223f2cf..62dc856be82 100644
--- a/src/test/ui/pattern/issue-71042-opaquely-typed-constant-used-in-pattern.stderr
+++ b/src/test/ui/pattern/issue-71042-opaquely-typed-constant-used-in-pattern.stderr
@@ -1,7 +1,7 @@
-error: opaque types cannot be used in patterns
+error: `impl Copy` cannot be used in patterns
   --> $DIR/issue-71042-opaquely-typed-constant-used-in-pattern.rs:7:9
    |
-LL |         C | _ => {}
+LL |         C |
    |         ^
 
 error: aborting due to previous error
diff --git a/src/test/ui/pattern/usefulness/exhaustive_integer_patterns.rs b/src/test/ui/pattern/usefulness/exhaustive_integer_patterns.rs
index d379dc44bf1..78cc0d28fb0 100644
--- a/src/test/ui/pattern/usefulness/exhaustive_integer_patterns.rs
+++ b/src/test/ui/pattern/usefulness/exhaustive_integer_patterns.rs
@@ -160,7 +160,7 @@ fn main() {
     match &0 {
         &42 => {}
         &FOO => {} //~ ERROR unreachable pattern
-        BAR => {} // Not detected as unreachable because `try_eval_bits` fails on `BAR`.
+        BAR => {} //~ ERROR unreachable pattern
         _ => {}
     }
 
diff --git a/src/test/ui/pattern/usefulness/exhaustive_integer_patterns.stderr b/src/test/ui/pattern/usefulness/exhaustive_integer_patterns.stderr
index de831520598..9f076c50a8f 100644
--- a/src/test/ui/pattern/usefulness/exhaustive_integer_patterns.stderr
+++ b/src/test/ui/pattern/usefulness/exhaustive_integer_patterns.stderr
@@ -135,6 +135,12 @@ error: unreachable pattern
 LL |         &FOO => {}
    |         ^^^^
 
-error: aborting due to 15 previous errors
+error: unreachable pattern
+  --> $DIR/exhaustive_integer_patterns.rs:163:9
+   |
+LL |         BAR => {}
+   |         ^^^
+
+error: aborting due to 16 previous errors
 
 For more information about this error, try `rustc --explain E0004`.
diff --git a/src/test/ui/pattern/usefulness/slice-pattern-const-2.rs b/src/test/ui/pattern/usefulness/slice-pattern-const-2.rs
index a36c550f530..4bf8d0fd2d3 100644
--- a/src/test/ui/pattern/usefulness/slice-pattern-const-2.rs
+++ b/src/test/ui/pattern/usefulness/slice-pattern-const-2.rs
@@ -6,19 +6,19 @@ fn main() {
     match s {
         MAGIC_TEST => (),
         [0x00, 0x00, 0x00, 0x00] => (),
-        [4, 5, 6, 7] => (), // FIXME(oli-obk): this should warn, but currently does not
+        [4, 5, 6, 7] => (), //~ ERROR unreachable pattern
         _ => (),
     }
     match s {
         [0x00, 0x00, 0x00, 0x00] => (),
         MAGIC_TEST => (),
-        [4, 5, 6, 7] => (), // FIXME(oli-obk): this should warn, but currently does not
+        [4, 5, 6, 7] => (), //~ ERROR unreachable pattern
         _ => (),
     }
     match s {
         [0x00, 0x00, 0x00, 0x00] => (),
         [4, 5, 6, 7] => (),
-        MAGIC_TEST => (), // FIXME(oli-obk): this should warn, but currently does not
+        MAGIC_TEST => (), //~ ERROR unreachable pattern
         _ => (),
     }
     const FOO: [u32; 1] = [4];
diff --git a/src/test/ui/pattern/usefulness/slice-pattern-const-2.stderr b/src/test/ui/pattern/usefulness/slice-pattern-const-2.stderr
index cd0cb2e8876..dcad11a38a7 100644
--- a/src/test/ui/pattern/usefulness/slice-pattern-const-2.stderr
+++ b/src/test/ui/pattern/usefulness/slice-pattern-const-2.stderr
@@ -1,8 +1,8 @@
 error: unreachable pattern
-  --> $DIR/slice-pattern-const-2.rs:28:9
+  --> $DIR/slice-pattern-const-2.rs:9:9
    |
-LL |         FOO => (),
-   |         ^^^
+LL |         [4, 5, 6, 7] => (),
+   |         ^^^^^^^^^^^^
    |
 note: the lint level is defined here
   --> $DIR/slice-pattern-const-2.rs:1:9
@@ -10,5 +10,23 @@ note: the lint level is defined here
 LL | #![deny(unreachable_patterns)]
    |         ^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to previous error
+error: unreachable pattern
+  --> $DIR/slice-pattern-const-2.rs:15:9
+   |
+LL |         [4, 5, 6, 7] => (),
+   |         ^^^^^^^^^^^^
+
+error: unreachable pattern
+  --> $DIR/slice-pattern-const-2.rs:21:9
+   |
+LL |         MAGIC_TEST => (),
+   |         ^^^^^^^^^^
+
+error: unreachable pattern
+  --> $DIR/slice-pattern-const-2.rs:28:9
+   |
+LL |         FOO => (),
+   |         ^^^
+
+error: aborting due to 4 previous errors
 
diff --git a/src/test/ui/pattern/usefulness/slice-pattern-const-3.rs b/src/test/ui/pattern/usefulness/slice-pattern-const-3.rs
index 8805c43ba02..2ca8323f002 100644
--- a/src/test/ui/pattern/usefulness/slice-pattern-const-3.rs
+++ b/src/test/ui/pattern/usefulness/slice-pattern-const-3.rs
@@ -6,19 +6,19 @@ fn main() {
     match s {
         MAGIC_TEST => (),
         ["0x00", "0x00", "0x00", "0x00"] => (),
-        ["4", "5", "6", "7"] => (), // FIXME(oli-obk): this should warn, but currently does not
+        ["4", "5", "6", "7"] => (), //~ ERROR unreachable pattern
         _ => (),
     }
     match s {
         ["0x00", "0x00", "0x00", "0x00"] => (),
         MAGIC_TEST => (),
-        ["4", "5", "6", "7"] => (), // FIXME(oli-obk): this should warn, but currently does not
+        ["4", "5", "6", "7"] => (), //~ ERROR unreachable pattern
         _ => (),
     }
     match s {
         ["0x00", "0x00", "0x00", "0x00"] => (),
         ["4", "5", "6", "7"] => (),
-        MAGIC_TEST => (), // FIXME(oli-obk): this should warn, but currently does not
+        MAGIC_TEST => (), //~ ERROR unreachable pattern
         _ => (),
     }
     const FOO: [&str; 1] = ["boo"];
diff --git a/src/test/ui/pattern/usefulness/slice-pattern-const-3.stderr b/src/test/ui/pattern/usefulness/slice-pattern-const-3.stderr
index 3ba01b9eba3..b90b3a88a18 100644
--- a/src/test/ui/pattern/usefulness/slice-pattern-const-3.stderr
+++ b/src/test/ui/pattern/usefulness/slice-pattern-const-3.stderr
@@ -1,8 +1,8 @@
 error: unreachable pattern
-  --> $DIR/slice-pattern-const-3.rs:28:9
+  --> $DIR/slice-pattern-const-3.rs:9:9
    |
-LL |         FOO => (),
-   |         ^^^
+LL |         ["4", "5", "6", "7"] => (),
+   |         ^^^^^^^^^^^^^^^^^^^^
    |
 note: the lint level is defined here
   --> $DIR/slice-pattern-const-3.rs:1:9
@@ -10,5 +10,23 @@ note: the lint level is defined here
 LL | #![deny(unreachable_patterns)]
    |         ^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to previous error
+error: unreachable pattern
+  --> $DIR/slice-pattern-const-3.rs:15:9
+   |
+LL |         ["4", "5", "6", "7"] => (),
+   |         ^^^^^^^^^^^^^^^^^^^^
+
+error: unreachable pattern
+  --> $DIR/slice-pattern-const-3.rs:21:9
+   |
+LL |         MAGIC_TEST => (),
+   |         ^^^^^^^^^^
+
+error: unreachable pattern
+  --> $DIR/slice-pattern-const-3.rs:28:9
+   |
+LL |         FOO => (),
+   |         ^^^
+
+error: aborting due to 4 previous errors
 
diff --git a/src/test/ui/pattern/usefulness/slice-patterns-exhaustiveness.rs b/src/test/ui/pattern/usefulness/slice-patterns-exhaustiveness.rs
index 52d1320dad1..46e0da5be9b 100644
--- a/src/test/ui/pattern/usefulness/slice-patterns-exhaustiveness.rs
+++ b/src/test/ui/pattern/usefulness/slice-patterns-exhaustiveness.rs
@@ -6,15 +6,15 @@ fn main() {
     let s10: &[bool; 10] = &[false; 10];
 
     match s2 {
-    //~^ ERROR `&[false, _]` not covered
+        //~^ ERROR `&[false, _]` not covered
         [true, .., true] => {}
     }
     match s3 {
-    //~^ ERROR `&[false, ..]` not covered
+        //~^ ERROR `&[false, ..]` not covered
         [true, .., true] => {}
     }
     match s10 {
-    //~^ ERROR `&[false, ..]` not covered
+        //~^ ERROR `&[false, ..]` not covered
         [true, .., true] => {}
     }
 
@@ -23,58 +23,58 @@ fn main() {
         [.., false] => {}
     }
     match s2 {
-    //~^ ERROR `&[false, true]` not covered
+        //~^ ERROR `&[false, true]` not covered
         [true, ..] => {}
         [.., false] => {}
     }
     match s3 {
-    //~^ ERROR `&[false, .., true]` not covered
+        //~^ ERROR `&[false, .., true]` not covered
         [true, ..] => {}
         [.., false] => {}
     }
     match s {
-    //~^ ERROR `&[false, .., true]` not covered
+        //~^ ERROR `&[false, .., true]` not covered
         [] => {}
         [true, ..] => {}
         [.., false] => {}
     }
 
     match s {
-    //~^ ERROR `&[_, ..]` not covered
+        //~^ ERROR `&[_, ..]` not covered
         [] => {}
     }
     match s {
-    //~^ ERROR `&[_, _, ..]` not covered
+        //~^ ERROR `&[_, _, ..]` not covered
         [] => {}
         [_] => {}
     }
     match s {
-    //~^ ERROR `&[false, ..]` not covered
+        //~^ ERROR `&[false, ..]` not covered
         [] => {}
         [true, ..] => {}
     }
     match s {
-    //~^ ERROR `&[false, _, ..]` not covered
+        //~^ ERROR `&[false, _, ..]` not covered
         [] => {}
         [_] => {}
         [true, ..] => {}
     }
     match s {
-    //~^ ERROR `&[_, .., false]` not covered
+        //~^ ERROR `&[_, .., false]` not covered
         [] => {}
         [_] => {}
         [.., true] => {}
     }
 
     match s {
-    //~^ ERROR `&[_, _, .., true]` not covered
+        //~^ ERROR `&[_, _, .., true]` not covered
         [] => {}
         [_] => {}
         [_, _] => {}
         [.., false] => {}
     }
     match s {
-    //~^ ERROR `&[true, _, .., _]` not covered
+        //~^ ERROR `&[true, _, .., _]` not covered
         [] => {}
         [_] => {}
         [_, _] => {}
@@ -83,19 +83,43 @@ fn main() {
 
     const CONST: &[bool] = &[true];
     match s {
-    //~^ ERROR `&[..]` not covered
+        //~^ ERROR `&[]` and `&[_, _, ..]` not covered
+        &[true] => {}
+    }
+    match s {
+        //~^ ERROR `&[]` and `&[_, _, ..]` not covered
+        CONST => {}
+    }
+    match s {
+        //~^ ERROR `&[]` and `&[_, _, ..]` not covered
         CONST => {}
+        &[false] => {}
     }
     match s {
-    //~^ ERROR `&[true]` not covered
-        [] => {},
-        [false] => {},
-        CONST => {},
+        //~^ ERROR `&[]` and `&[_, _, ..]` not covered
+        &[false] => {}
+        CONST => {}
+    }
+    match s {
+        //~^ ERROR `&[_, _, ..]` not covered
+        &[] => {}
+        CONST => {}
+    }
+    match s {
+        //~^ ERROR `&[false]` not covered
+        &[] => {}
+        CONST => {}
+        &[_, _, ..] => {}
+    }
+    match s {
+        [] => {}
+        [false] => {}
+        CONST => {}
         [_, _, ..] => {}
     }
     const CONST1: &[bool; 1] = &[true];
     match s1 {
-    //~^ ERROR `&[false]` not covered
+        //~^ ERROR `&[false]` not covered
         CONST1 => {}
     }
     match s1 {
diff --git a/src/test/ui/pattern/usefulness/slice-patterns-exhaustiveness.stderr b/src/test/ui/pattern/usefulness/slice-patterns-exhaustiveness.stderr
index 8b85eaeda0a..e34770fb912 100644
--- a/src/test/ui/pattern/usefulness/slice-patterns-exhaustiveness.stderr
+++ b/src/test/ui/pattern/usefulness/slice-patterns-exhaustiveness.stderr
@@ -115,26 +115,62 @@ LL |     match s {
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
    = note: the matched value is of type `&[bool]`
 
-error[E0004]: non-exhaustive patterns: `&[..]` not covered
+error[E0004]: non-exhaustive patterns: `&[]` and `&[_, _, ..]` not covered
   --> $DIR/slice-patterns-exhaustiveness.rs:85:11
    |
 LL |     match s {
-   |           ^ pattern `&[..]` not covered
+   |           ^ patterns `&[]` and `&[_, _, ..]` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
    = note: the matched value is of type `&[bool]`
 
-error[E0004]: non-exhaustive patterns: `&[true]` not covered
+error[E0004]: non-exhaustive patterns: `&[]` and `&[_, _, ..]` not covered
   --> $DIR/slice-patterns-exhaustiveness.rs:89:11
    |
 LL |     match s {
-   |           ^ pattern `&[true]` not covered
+   |           ^ patterns `&[]` and `&[_, _, ..]` not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   = note: the matched value is of type `&[bool]`
+
+error[E0004]: non-exhaustive patterns: `&[]` and `&[_, _, ..]` not covered
+  --> $DIR/slice-patterns-exhaustiveness.rs:93:11
+   |
+LL |     match s {
+   |           ^ patterns `&[]` and `&[_, _, ..]` not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   = note: the matched value is of type `&[bool]`
+
+error[E0004]: non-exhaustive patterns: `&[]` and `&[_, _, ..]` not covered
+  --> $DIR/slice-patterns-exhaustiveness.rs:98:11
+   |
+LL |     match s {
+   |           ^ patterns `&[]` and `&[_, _, ..]` not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   = note: the matched value is of type `&[bool]`
+
+error[E0004]: non-exhaustive patterns: `&[_, _, ..]` not covered
+  --> $DIR/slice-patterns-exhaustiveness.rs:103:11
+   |
+LL |     match s {
+   |           ^ pattern `&[_, _, ..]` not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   = note: the matched value is of type `&[bool]`
+
+error[E0004]: non-exhaustive patterns: `&[false]` not covered
+  --> $DIR/slice-patterns-exhaustiveness.rs:108:11
+   |
+LL |     match s {
+   |           ^ pattern `&[false]` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
    = note: the matched value is of type `&[bool]`
 
 error[E0004]: non-exhaustive patterns: `&[false]` not covered
-  --> $DIR/slice-patterns-exhaustiveness.rs:97:11
+  --> $DIR/slice-patterns-exhaustiveness.rs:121:11
    |
 LL |     match s1 {
    |           ^^ pattern `&[false]` not covered
@@ -142,6 +178,6 @@ LL |     match s1 {
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
    = note: the matched value is of type `&[bool; 1]`
 
-error: aborting due to 16 previous errors
+error: aborting due to 20 previous errors
 
 For more information about this error, try `rustc --explain E0004`.