diff --git a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs index 01671eb5ce367..61072735e18f0 100644 --- a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs +++ b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs @@ -4,6 +4,13 @@ enum Foo {} struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here +union NonEmptyUnion1 { + foo: (), +} +union NonEmptyUnion2 { + foo: (), + bar: (), +} enum NonEmptyEnum1 { //~ `NonEmptyEnum1` defined here Foo(bool), //~ variant not covered } @@ -36,6 +43,10 @@ fn main() { //~^ ERROR type `u8` is non-empty match NonEmptyStruct(true) {} //~^ ERROR pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled + match (NonEmptyUnion1 { foo: () }) {} + //~^ ERROR pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled + match (NonEmptyUnion2 { foo: () }) {} + //~^ ERROR pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled match NonEmptyEnum1::Foo(true) {} //~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled match NonEmptyEnum2::Foo(true) {} diff --git a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr index d126b9185d109..82be26cfd873c 100644 --- a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr +++ b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr @@ -1,5 +1,5 @@ error: unreachable pattern - --> $DIR/match-empty-exhaustive_patterns.rs:21:9 + --> $DIR/match-empty-exhaustive_patterns.rs:28:9 | LL | _ => {}, | ^ @@ -11,19 +11,19 @@ LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/match-empty-exhaustive_patterns.rs:28:9 + --> $DIR/match-empty-exhaustive_patterns.rs:35:9 | LL | Some(_) => {} | ^^^^^^^ error: unreachable pattern - --> $DIR/match-empty-exhaustive_patterns.rs:32:9 + --> $DIR/match-empty-exhaustive_patterns.rs:39:9 | LL | Some(_) => {} | ^^^^^^^ error[E0004]: non-exhaustive patterns: type `u8` is non-empty - --> $DIR/match-empty-exhaustive_patterns.rs:35:11 + --> $DIR/match-empty-exhaustive_patterns.rs:42:11 | LL | match 0u8 {} | ^^^ @@ -31,7 +31,7 @@ LL | match 0u8 {} = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled - --> $DIR/match-empty-exhaustive_patterns.rs:37:11 + --> $DIR/match-empty-exhaustive_patterns.rs:44:11 | LL | struct NonEmptyStruct(bool); | ---------------------------- @@ -44,8 +44,41 @@ LL | match NonEmptyStruct(true) {} | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms +error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled + --> $DIR/match-empty-exhaustive_patterns.rs:46:11 + | +LL | union NonEmptyUnion1 { + | - -------------- variant not covered + | _| + | | +LL | | foo: (), +LL | | } + | |_- `NonEmptyUnion1` defined here +... +LL | match (NonEmptyUnion1 { foo: () }) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled + --> $DIR/match-empty-exhaustive_patterns.rs:48:11 + | +LL | union NonEmptyUnion2 { + | - -------------- variant not covered + | _| + | | +LL | | foo: (), +LL | | bar: (), +LL | | } + | |_- `NonEmptyUnion2` defined here +... +LL | match (NonEmptyUnion2 { foo: () }) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + error[E0004]: non-exhaustive patterns: pattern `Foo` of type `NonEmptyEnum1` is not handled - --> $DIR/match-empty-exhaustive_patterns.rs:39:11 + --> $DIR/match-empty-exhaustive_patterns.rs:50:11 | LL | / enum NonEmptyEnum1 { LL | | Foo(bool), @@ -59,7 +92,7 @@ LL | match NonEmptyEnum1::Foo(true) {} = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum2` are not handled - --> $DIR/match-empty-exhaustive_patterns.rs:41:11 + --> $DIR/match-empty-exhaustive_patterns.rs:52:11 | LL | / enum NonEmptyEnum2 { LL | | Foo(bool), @@ -75,7 +108,7 @@ LL | match NonEmptyEnum2::Foo(true) {} = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum5` are not handled - --> $DIR/match-empty-exhaustive_patterns.rs:43:11 + --> $DIR/match-empty-exhaustive_patterns.rs:54:11 | LL | / enum NonEmptyEnum5 { LL | | V1, V2, V3, V4, V5, @@ -87,6 +120,6 @@ LL | match NonEmptyEnum5::V1 {} | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors For more information about this error, try `rustc --explain E0004`. diff --git a/src/test/ui/pattern/usefulness/match-empty.rs b/src/test/ui/pattern/usefulness/match-empty.rs index 178d72d11584b..ebbc1358cdbe4 100644 --- a/src/test/ui/pattern/usefulness/match-empty.rs +++ b/src/test/ui/pattern/usefulness/match-empty.rs @@ -3,6 +3,13 @@ enum Foo {} struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here +union NonEmptyUnion1 { + foo: (), +} +union NonEmptyUnion2 { + foo: (), + bar: (), +} enum NonEmptyEnum1 { //~ `NonEmptyEnum1` defined here Foo(bool), //~ variant not covered } @@ -20,7 +27,7 @@ fn foo1(x: Foo) { fn foo2(x: Foo) { match x { - _ => {}, // FIXME: should be unreachable + _ => {}, // Not detected as unreachable, see #55123. } } @@ -39,6 +46,10 @@ fn main() { //~^ ERROR type `u8` is non-empty match NonEmptyStruct(true) {} //~^ ERROR pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled + match (NonEmptyUnion1 { foo: () }) {} + //~^ ERROR pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled + match (NonEmptyUnion2 { foo: () }) {} + //~^ ERROR pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled match NonEmptyEnum1::Foo(true) {} //~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled match NonEmptyEnum2::Foo(true) {} diff --git a/src/test/ui/pattern/usefulness/match-empty.stderr b/src/test/ui/pattern/usefulness/match-empty.stderr index 7d220a31ff969..4ba1c79b4b2db 100644 --- a/src/test/ui/pattern/usefulness/match-empty.stderr +++ b/src/test/ui/pattern/usefulness/match-empty.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: type `u8` is non-empty - --> $DIR/match-empty.rs:38:11 + --> $DIR/match-empty.rs:45:11 | LL | match 0u8 {} | ^^^ @@ -7,7 +7,7 @@ LL | match 0u8 {} = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled - --> $DIR/match-empty.rs:40:11 + --> $DIR/match-empty.rs:47:11 | LL | struct NonEmptyStruct(bool); | ---------------------------- @@ -20,8 +20,41 @@ LL | match NonEmptyStruct(true) {} | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms +error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled + --> $DIR/match-empty.rs:49:11 + | +LL | union NonEmptyUnion1 { + | - -------------- variant not covered + | _| + | | +LL | | foo: (), +LL | | } + | |_- `NonEmptyUnion1` defined here +... +LL | match (NonEmptyUnion1 { foo: () }) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled + --> $DIR/match-empty.rs:51:11 + | +LL | union NonEmptyUnion2 { + | - -------------- variant not covered + | _| + | | +LL | | foo: (), +LL | | bar: (), +LL | | } + | |_- `NonEmptyUnion2` defined here +... +LL | match (NonEmptyUnion2 { foo: () }) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + error[E0004]: non-exhaustive patterns: pattern `Foo` of type `NonEmptyEnum1` is not handled - --> $DIR/match-empty.rs:42:11 + --> $DIR/match-empty.rs:53:11 | LL | / enum NonEmptyEnum1 { LL | | Foo(bool), @@ -35,7 +68,7 @@ LL | match NonEmptyEnum1::Foo(true) {} = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum2` are not handled - --> $DIR/match-empty.rs:44:11 + --> $DIR/match-empty.rs:55:11 | LL | / enum NonEmptyEnum2 { LL | | Foo(bool), @@ -51,7 +84,7 @@ LL | match NonEmptyEnum2::Foo(true) {} = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum5` are not handled - --> $DIR/match-empty.rs:46:11 + --> $DIR/match-empty.rs:57:11 | LL | / enum NonEmptyEnum5 { LL | | V1, V2, V3, V4, V5, @@ -63,6 +96,6 @@ LL | match NonEmptyEnum5::V1 {} | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error: aborting due to 5 previous errors +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0004`.