From: Philip Herron Date: Wed, 29 Mar 2023 21:27:38 +0000 (+0100) Subject: gccrs: Add testcase to show matching of enum variants X-Git-Tag: basepoints/gcc-15~2645 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c1da49edb8e8318c91bada12b4b28f25b10dd1c1;p=thirdparty%2Fgcc.git gccrs: Add testcase to show matching of enum variants Fixes #852 gcc/testsuite/ChangeLog: * rust/compile/issue-852.rs: New test. Signed-off-by: Philip Herron --- diff --git a/gcc/testsuite/rust/compile/issue-852.rs b/gcc/testsuite/rust/compile/issue-852.rs new file mode 100644 index 000000000000..763105d27497 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-852.rs @@ -0,0 +1,30 @@ +// { dg-options "-w" } +extern "C" { + fn printf(s: *const i8, ...); +} + +enum Foo { + A, + B(i32), +} + +fn main() { + let result = Foo::B(123); + + match result { + A => unsafe { + let a = "A\n\0"; + let b = a as *const str; + let c = b as *const i8; + + printf(c); + }, + Foo::B(x) => unsafe { + let a = "Result: %i\n\0"; + let b = a as *const str; + let c = b as *const i8; + + printf(c, x); + }, + } +}