Skip to content

Commit

Permalink
Rollup merge of #91281 - scottmcm:non-exhaustive-as-test, r=Mark-Simu…
Browse files Browse the repository at this point in the history
…lacrum

Add demonstration test for #91161

Since cross-crate things are hard to demonstrate in playground, here's a test showing that something currently works that shouldn't.

cc #91161 that tracks fixing the problem (and updating this test)
  • Loading branch information
matthiaskrgr committed Nov 29, 2021
2 parents 80277dc + 50619f5 commit a2f924a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/test/ui/rfc-2008-non-exhaustive/auxiliary/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
17 changes: 17 additions & 0 deletions src/test/ui/rfc-2008-non-exhaustive/enum-as-cast.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit a2f924a

Please sign in to comment.