2021-06-29 19:22:52 -05:00
|
|
|
// 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),
|
|
|
|
}
|
|
|
|
|
2021-06-29 19:22:52 -05:00
|
|
|
fn main() {
|
|
|
|
assert_eq!(Foo::default(), Foo::Alpha);
|
2022-08-26 08:00:38 -05:00
|
|
|
assert!(matches!(MyOption::<NotDefault>::default(), MyOption::None));
|
2021-06-29 19:22:52 -05:00
|
|
|
}
|