4 use enums::{EmptyNonExhaustiveEnum, NonExhaustiveEnum};
6 fn empty(x: EmptyNonExhaustiveEnum) {
7 match x {} //~ ERROR type `EmptyNonExhaustiveEnum` is non-empty
14 let enum_unit = NonExhaustiveEnum::Unit;
17 //~^ ERROR non-exhaustive patterns: `_` not covered [E0004]
18 NonExhaustiveEnum::Unit => "first",
19 NonExhaustiveEnum::Tuple(_) => "second",
20 NonExhaustiveEnum::Struct { .. } => "third"
24 //~^ ERROR non-exhaustive patterns: `_` not covered [E0004]
26 // Everything below this is expected to compile successfully.
28 let enum_unit = NonExhaustiveEnum::Unit;
31 NonExhaustiveEnum::Unit => 1,
32 NonExhaustiveEnum::Tuple(_) => 2,
33 // This particular arm tests that an enum marked as non-exhaustive
34 // will not error if its variants are matched exhaustively.
35 NonExhaustiveEnum::Struct { field } => field,
36 _ => 0 // no error with wildcard
40 _ => "no error with only wildcard"
43 // #53549: Check that variant constructors can still be called normally.
44 match NonExhaustiveEnum::Unit {
45 NonExhaustiveEnum::Unit => {},
49 match NonExhaustiveEnum::Tuple(2) {
50 NonExhaustiveEnum::Tuple(2) => {},
54 match (NonExhaustiveEnum::Unit {}) {
55 NonExhaustiveEnum::Unit {} => {},
59 match (NonExhaustiveEnum::Tuple { 0: 2 }) {
60 NonExhaustiveEnum::Tuple { 0: 2 } => {},
64 match (NonExhaustiveEnum::Struct { field: 2 }) {
65 NonExhaustiveEnum::Struct { field: 2 } => {},