Skip to content

Commit 50619f5

Browse files
committed
Demonstration test for #91161
1 parent f7c4829 commit 50619f5

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/test/ui/rfc-2008-non-exhaustive/auxiliary/enums.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,15 @@ pub enum VariantNonExhaustive {
3030
pub enum NonExhaustiveSingleVariant {
3131
A(bool),
3232
}
33+
34+
#[repr(u8)]
35+
pub enum FieldLessWithNonExhaustiveVariant {
36+
A,
37+
B,
38+
#[non_exhaustive]
39+
C,
40+
}
41+
42+
impl Default for FieldLessWithNonExhaustiveVariant {
43+
fn default() -> Self { Self::A }
44+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// aux-build:enums.rs
2+
// run-pass
3+
4+
extern crate enums;
5+
6+
use enums::FieldLessWithNonExhaustiveVariant;
7+
8+
fn main() {
9+
let e = FieldLessWithNonExhaustiveVariant::default();
10+
// FIXME: https://github.com/rust-lang/rust/issues/91161
11+
// This `as` cast *should* be an error, since it would fail
12+
// if the non-exhaustive variant got fields. But today it
13+
// doesn't. The fix for that will update this test to
14+
// show an error (and not be run-pass any more).
15+
let d = e as u8;
16+
assert_eq!(d, 0);
17+
}

0 commit comments

Comments
 (0)