diff options
| author | dianqk <dianqk@dianqk.net> | 2025-06-30 19:23:17 +0800 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-30 19:23:17 +0800 | 
| commit | 0952f86de31f90b0e9f2bc700243fcc711990aa9 (patch) | |
| tree | 3fd1ced5b745ab0c85c5b6a5d9fe26e69d7319d9 /tests/ui/derives/derive-Debug-enum-variants.rs | |
| parent | a94f0a4af8a1c11c1934ee8ba44d59fb5da77d4b (diff) | |
| parent | 580bc128441236345a5f3d5022af5a60091451ac (diff) | |
| download | rust-0952f86de31f90b0e9f2bc700243fcc711990aa9.tar.gz rust-0952f86de31f90b0e9f2bc700243fcc711990aa9.zip  | |
Rollup merge of #143118 - Kivooeo:tf15, r=tgross35
`tests/ui`: A New Order [15/N] > [!NOTE] > > Intermediate commits are intended to help review, but will be squashed prior to merge. Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of rust-lang/rust#133895. r? `@jieyouxu`
Diffstat (limited to 'tests/ui/derives/derive-Debug-enum-variants.rs')
| -rw-r--r-- | tests/ui/derives/derive-Debug-enum-variants.rs | 30 | 
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/ui/derives/derive-Debug-enum-variants.rs b/tests/ui/derives/derive-Debug-enum-variants.rs new file mode 100644 index 00000000000..26f527f7664 --- /dev/null +++ b/tests/ui/derives/derive-Debug-enum-variants.rs @@ -0,0 +1,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)); +}  | 
