diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2021-11-26 19:27:40 -0800 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2021-11-26 19:27:40 -0800 |
| commit | 50619f568a250750fcb6bea271ccfd8fdc0926bf (patch) | |
| tree | b735534f2041bec7734dc6ae1ba5317f21d1bd82 | |
| parent | f7c48297ce21ac0dc5b36ff730377bdb7be6ece4 (diff) | |
| download | rust-50619f568a250750fcb6bea271ccfd8fdc0926bf.tar.gz rust-50619f568a250750fcb6bea271ccfd8fdc0926bf.zip | |
Demonstration test for #91161
| -rw-r--r-- | src/test/ui/rfc-2008-non-exhaustive/auxiliary/enums.rs | 12 | ||||
| -rw-r--r-- | src/test/ui/rfc-2008-non-exhaustive/enum-as-cast.rs | 17 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/test/ui/rfc-2008-non-exhaustive/auxiliary/enums.rs b/src/test/ui/rfc-2008-non-exhaustive/auxiliary/enums.rs index 0098f087d10..cb2b585ab96 100644 --- a/src/test/ui/rfc-2008-non-exhaustive/auxiliary/enums.rs +++ b/src/test/ui/rfc-2008-non-exhaustive/auxiliary/enums.rs @@ -30,3 +30,15 @@ pub enum VariantNonExhaustive { pub enum NonExhaustiveSingleVariant { A(bool), } + +#[repr(u8)] +pub enum FieldLessWithNonExhaustiveVariant { + A, + B, + #[non_exhaustive] + C, +} + +impl Default for FieldLessWithNonExhaustiveVariant { + fn default() -> Self { Self::A } +} diff --git a/src/test/ui/rfc-2008-non-exhaustive/enum-as-cast.rs b/src/test/ui/rfc-2008-non-exhaustive/enum-as-cast.rs new file mode 100644 index 00000000000..d9657bac776 --- /dev/null +++ b/src/test/ui/rfc-2008-non-exhaustive/enum-as-cast.rs @@ -0,0 +1,17 @@ +// aux-build:enums.rs +// run-pass + +extern crate enums; + +use enums::FieldLessWithNonExhaustiveVariant; + +fn main() { + let e = FieldLessWithNonExhaustiveVariant::default(); + // FIXME: https://github.com/rust-lang/rust/issues/91161 + // This `as` cast *should* be an error, since it would fail + // if the non-exhaustive variant got fields. But today it + // doesn't. The fix for that will update this test to + // show an error (and not be run-pass any more). + let d = e as u8; + assert_eq!(d, 0); +} |
