Debian Codegraph @

gcc/testsuite/rust/execute/torture/match1.rs

raw
1 // { dg-output "Foo::A\r*\nFoo::B\r*\nFoo::C x\r*\nFoo::D 20 80\r*\n" }
2 extern "C" {
3 fn printf(s: *const i8, ...);
4 }
5
6 enum Foo {
7 A,
8 B,
9 C(char),
10 D { x: i32, y: i32 },
11 }
12
13 fn inspect(f: Foo) {
14 match f {
15 Foo::A => unsafe {
16 let a = "Foo::A\n\0";
17 let b = a as *const str;
18 let c = b as *const i8;
19
20 printf(c);
21 },
22 Foo::B => unsafe {
23 let a = "Foo::B\n\0";
24 let b = a as *const str;
25 let c = b as *const i8;
26
27 printf(c);
28 },
29 Foo::C(x) => unsafe {
30 let a = "Foo::C %c\n\0";
31 let b = a as *const str;
32 let c = b as *const i8;
33
34 printf(c, x);
35 },
36 Foo::D { x, y } => unsafe {
37 let a = "Foo::D %i %i\n\0";
38 let b = a as *const str;
39 let c = b as *const i8;
40
41 printf(c, x, y);
42 },
43 }
44 }
45
46 fn main() -> i32 {
47 let a = Foo::A;
48 let b = Foo::B;
49 let c = Foo::C('x');
50 let d = Foo::D { x: 20, y: 80 };
51
52 inspect(a);
53 inspect(b);
54 inspect(c);
55 inspect(d);
56
57 0
58 }