10 fn test1(c: CEnum) -> i32 {
11 let c2 = CEnum::Hello;
13 (CEnum::Hello, CEnum::Hello) => 42,
14 (CEnum::World, CEnum::Hello) => 0,
28 // It is unsafe to use #[derive(Debug)] on a packed struct because the code generated by the derive
29 // macro takes references to the fields instead of accessing them directly.
30 impl fmt::Debug for Pakd {
31 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32 // It's important that we load the fields into locals by-value here. This will do safe
33 // unaligned loads into the locals, then pass references to the properly-aligned locals to
34 // the formatting code.
35 let Pakd { a, b, c, d, e } = *self;
36 f.debug_struct("Pakd")
46 // It is unsafe to use #[derive(PartialEq)] on a packed struct because the code generated by the
47 // derive macro takes references to the fields instead of accessing them directly.
48 impl PartialEq for Pakd {
49 fn eq(&self, other: &Pakd) -> bool {
63 Pakd { a: 42, b: 42, c: 42, d: 42, e: () }
66 #[derive(PartialEq, Debug)]
67 struct TupleLike(u64, u32);
69 fn test3() -> TupleLike {
73 fn test4(x: fn(u64, u32) -> TupleLike) -> (TupleLike, TupleLike) {
75 (x(42, 84), y(42, 84))
78 fn test5(x: fn(u32) -> Option<u32>) -> (Option<u32>, Option<u32>) {
84 assert_eq!(test1(CEnum::Hello), 42);
85 assert_eq!(test1(CEnum::World), 0);
86 assert_eq!(test2(), Pakd { a: 42, b: 42, c: 42, d: 42, e: () });
87 assert_eq!(test3(), TupleLike(42, 42));
88 let t4 = test4(TupleLike);
89 assert_eq!(t4.0, t4.1);
91 assert_eq!(t5.0, t5.1);