summaryrefslogtreecommitdiffstats
path: root/tests/ui/deriving/deriving-default-enum.rs
blob: 1c7a501edc7055b30032b44f164c1e514bd15428 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// 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),
}

// #[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);
    assert!(matches!(MyOption::<NotDefault>::default(), MyOption::None));
}