about summary refs log tree commit diff
path: root/tests/ui/derives/derive-Debug-enum-variants.rs
blob: 26f527f766411a73456acb82e08ae0738aa48ea9 (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
28
29
30
//! Test that `#[derive(Debug)]` for enums correctly formats variant names.

//@ run-pass

#[derive(Debug)]
enum Foo {
    A(usize),
    C,
}

#[derive(Debug)]
enum Bar {
    D,
}

pub fn main() {
    // Test variant with data
    let foo_a = Foo::A(22);
    assert_eq!("A(22)".to_string(), format!("{:?}", foo_a));

    if let Foo::A(value) = foo_a {
        println!("Value: {}", value); // This needs to remove #[allow(dead_code)]
    }

    // Test unit variant
    assert_eq!("C".to_string(), format!("{:?}", Foo::C));

    // Test unit variant from different enum
    assert_eq!("D".to_string(), format!("{:?}", Bar::D));
}