about summary refs log tree commit diff
path: root/tests/ui/pattern
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2024-03-31 23:57:53 +0200
committerNadrieril <nadrieril+git@gmail.com>2024-04-01 00:01:46 +0200
commit27704c7f9eea6e8ffaedac04ae1c932da7422fb7 (patch)
tree1c2d72a59e37bd00c02652feab63be38d99332eb /tests/ui/pattern
parentdb9b4eac480525d7af188a8360371d3cef84de98 (diff)
downloadrust-27704c7f9eea6e8ffaedac04ae1c932da7422fb7.tar.gz
rust-27704c7f9eea6e8ffaedac04ae1c932da7422fb7.zip
Fix union handling in exhaustiveness
Diffstat (limited to 'tests/ui/pattern')
-rw-r--r--tests/ui/pattern/usefulness/unions.rs5
-rw-r--r--tests/ui/pattern/usefulness/unions.stderr18
2 files changed, 12 insertions, 11 deletions
diff --git a/tests/ui/pattern/usefulness/unions.rs b/tests/ui/pattern/usefulness/unions.rs
index 32fe9b4c04d..80a7f36a09a 100644
--- a/tests/ui/pattern/usefulness/unions.rs
+++ b/tests/ui/pattern/usefulness/unions.rs
@@ -20,12 +20,13 @@ fn main() {
             U8AsBool { n: 1.. } => {}
         }
         match x {
-            //~^ ERROR non-exhaustive patterns: `U8AsBool { n: 0_u8, b: false }` not covered
+            //~^ ERROR non-exhaustive patterns: `U8AsBool { n: 0_u8 }` and `U8AsBool { b: false }` not covered
             U8AsBool { b: true } => {}
             U8AsBool { n: 1.. } => {}
         }
+        // Our approach can report duplicate witnesses sometimes.
         match (x, true) {
-            //~^ ERROR non-exhaustive patterns: `(U8AsBool { n: 0_u8, b: false }, false)` and `(U8AsBool { n: 0_u8, b: true }, false)` not covered
+            //~^ ERROR non-exhaustive patterns: `(U8AsBool { n: 0_u8 }, false)`, `(U8AsBool { b: false }, false)`, `(U8AsBool { n: 0_u8 }, false)` and 1 more not covered
             (U8AsBool { b: true }, true) => {}
             (U8AsBool { b: false }, true) => {}
             (U8AsBool { n: 1.. }, true) => {}
diff --git a/tests/ui/pattern/usefulness/unions.stderr b/tests/ui/pattern/usefulness/unions.stderr
index d824a031cd3..4b397dc25db 100644
--- a/tests/ui/pattern/usefulness/unions.stderr
+++ b/tests/ui/pattern/usefulness/unions.stderr
@@ -1,8 +1,8 @@
-error[E0004]: non-exhaustive patterns: `U8AsBool { n: 0_u8, b: false }` not covered
+error[E0004]: non-exhaustive patterns: `U8AsBool { n: 0_u8 }` and `U8AsBool { b: false }` not covered
   --> $DIR/unions.rs:22:15
    |
 LL |         match x {
-   |               ^ pattern `U8AsBool { n: 0_u8, b: false }` not covered
+   |               ^ patterns `U8AsBool { n: 0_u8 }` and `U8AsBool { b: false }` not covered
    |
 note: `U8AsBool` defined here
   --> $DIR/unions.rs:3:11
@@ -10,23 +10,23 @@ note: `U8AsBool` defined here
 LL |     union U8AsBool {
    |           ^^^^^^^^
    = note: the matched value is of type `U8AsBool`
-help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
+help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
    |
 LL ~             U8AsBool { n: 1.. } => {},
-LL +             U8AsBool { n: 0_u8, b: false } => todo!()
+LL +             U8AsBool { n: 0_u8 } | U8AsBool { b: false } => todo!()
    |
 
-error[E0004]: non-exhaustive patterns: `(U8AsBool { n: 0_u8, b: false }, false)` and `(U8AsBool { n: 0_u8, b: true }, false)` not covered
-  --> $DIR/unions.rs:27:15
+error[E0004]: non-exhaustive patterns: `(U8AsBool { n: 0_u8 }, false)`, `(U8AsBool { b: false }, false)`, `(U8AsBool { n: 0_u8 }, false)` and 1 more not covered
+  --> $DIR/unions.rs:28:15
    |
 LL |         match (x, true) {
-   |               ^^^^^^^^^ patterns `(U8AsBool { n: 0_u8, b: false }, false)` and `(U8AsBool { n: 0_u8, b: true }, false)` not covered
+   |               ^^^^^^^^^ patterns `(U8AsBool { n: 0_u8 }, false)`, `(U8AsBool { b: false }, false)`, `(U8AsBool { n: 0_u8 }, false)` and 1 more not covered
    |
    = note: the matched value is of type `(U8AsBool, bool)`
-help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
+help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown, or multiple match arms
    |
 LL ~             (U8AsBool { n: 1.. }, true) => {},
-LL +             (U8AsBool { n: 0_u8, b: false }, false) | (U8AsBool { n: 0_u8, b: true }, false) => todo!()
+LL +             _ => todo!()
    |
 
 error: aborting due to 2 previous errors