1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_unsafe)]
4 // Issue #2303
5
6 #![feature(intrinsics)]
7
8 use std::mem;
9
10 mod rusti {
11 extern "rust-intrinsic" {
pref_align_of<T>() -> usize12 pub fn pref_align_of<T>() -> usize;
min_align_of<T>() -> usize13 pub fn min_align_of<T>() -> usize;
14 }
15 }
16
17 // This is the type with the questionable alignment
18 #[derive(Debug)]
19 struct Inner {
20 c64: u32
21 }
22
23 // This is the type that contains the type with the
24 // questionable alignment, for testing
25 #[derive(Debug)]
26 struct Outer {
27 c8: u8,
28 t: Inner
29 }
30
31 mod m {
align() -> usize32 pub fn align() -> usize { 4 }
size() -> usize33 pub fn size() -> usize { 8 }
34 }
35
main()36 pub fn main() {
37 unsafe {
38 let x = Outer {c8: 22, t: Inner {c64: 44}};
39
40 // Send it through the shape code
41 let y = format!("{:?}", x);
42
43 println!("align inner = {:?}", rusti::min_align_of::<Inner>());
44 println!("size outer = {:?}", mem::size_of::<Outer>());
45 println!("y = {:?}", y);
46
47 // per clang/gcc the alignment of `inner` is 4 on x86.
48 assert_eq!(rusti::min_align_of::<Inner>(), m::align());
49
50 // per clang/gcc the size of `outer` should be 12
51 // because `inner`s alignment was 4.
52 assert_eq!(mem::size_of::<Outer>(), m::size());
53
54 assert_eq!(y, "Outer { c8: 22, t: Inner { c64: 44 } }".to_string());
55 }
56 }
57