fix is_non_exhaustive confusion between structs and enums

Structs and enums can both be non-exhaustive, with a very different
meaning. This PR splits `is_non_exhaustive` to 2 separate functions - 1
for structs, and another for enums, and fixes the places that got the
usage confused.

Fixes #53549.
This commit is contained in:
Ariel Ben-Yehuda 2018-08-26 16:36:50 +03:00
parent caed80ba4b
commit 993e7e2622
7 changed files with 87 additions and 24 deletions

View file

@ -30,4 +30,33 @@ fn main() {
match enum_unit {
_ => "no error with only wildcard"
};
// issue #53549 - check that variant constructors can still be called normally.
match NonExhaustiveEnum::Unit {
NonExhaustiveEnum::Unit => {},
_ => {}
};
match NonExhaustiveEnum::Tuple(2) {
NonExhaustiveEnum::Tuple(2) => {},
_ => {}
};
match (NonExhaustiveEnum::Unit {}) {
NonExhaustiveEnum::Unit {} => {},
_ => {}
};
match (NonExhaustiveEnum::Tuple { 0: 2 }) {
NonExhaustiveEnum::Tuple { 0: 2 } => {},
_ => {}
};
match (NonExhaustiveEnum::Struct { field: 2 }) {
NonExhaustiveEnum::Struct { field: 2 } => {},
_ => {}
};
}