2 #![allow(non_upper_case_globals)]
6 // For simplicity of explanations assuming code is compiled for x86_64
9 // Size of TestOption<u64> is 16, and alignment of TestOption<u64> is 8.
10 // Size of u8 is 1, and alignment of u8 is 1.
11 // So size of Request is 24, and alignment of Request must be 8:
12 // the maximum alignment of its fields.
13 // Last 7 bytes of Request struct are not occupied by any fields.
27 fn default_instance() -> &'static Request {
28 static instance: Request = Request {
29 // LLVM does not allow to specify alignment of expressions, thus
30 // alignment of `foo` in constant is 1, not 8.
31 foo: TestOption::TestNone,
33 // Space after last field is not occupied by any data, but it is
34 // reserved to make struct aligned properly. If compiler does
35 // not insert padding after last field when emitting constant,
36 // size of struct may be not equal to size of struct, and
37 // compiler crashes in internal assertion check.
42 fn non_default_instance() -> &'static Request {
43 static instance: Request = Request {
44 foo: TestOption::TestSome(0x1020304050607080),
51 match default_instance() {
52 &Request { foo: TestOption::TestNone, bar: 17 } => {},
55 match non_default_instance() {
56 &Request { foo: TestOption::TestSome(0x1020304050607080), bar: 19 } => {},