Demonstration test for #91161
This commit is contained in:
parent
f7c48297ce
commit
50619f568a
2 changed files with 29 additions and 0 deletions
|
|
@ -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
src/test/ui/rfc-2008-non-exhaustive/enum-as-cast.rs
Normal file
17
src/test/ui/rfc-2008-non-exhaustive/enum-as-cast.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue