rust/tests/ui/deriving/deriving-default-enum.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
530 B
Rust
Raw Normal View History

// run-pass
// nb: does not impl Default
#[derive(Debug, PartialEq)]
struct NotDefault;
#[derive(Debug, Default, PartialEq)]
enum Foo {
#[default]
Alpha,
#[allow(dead_code)]
Beta(NotDefault),
}
2022-08-26 08:00:38 -05:00
// #[default] on a generic enum does not add `Default` bounds to the type params.
#[derive(Default)]
enum MyOption<T> {
#[default]
None,
#[allow(dead_code)]
Some(T),
}
fn main() {
assert_eq!(Foo::default(), Foo::Alpha);
2022-08-26 08:00:38 -05:00
assert!(matches!(MyOption::<NotDefault>::default(), MyOption::None));
}