1 #![allow(
2 dead_code,
3 non_snake_case,
4 non_camel_case_types,
5 non_upper_case_globals
6 )]
7
8 #[repr(C)]
9 #[derive(Debug, Copy, Clone)]
10 pub struct Foo {
11 _unused: [u8; 0],
12 }
13 #[repr(C)]
14 #[derive(Debug, Copy, Clone)]
15 pub struct RefPtr<T> {
16 pub m_inner: *mut T,
17 pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
18 }
19 impl<T> Default for RefPtr<T> {
default() -> Self20 fn default() -> Self {
21 let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
22 unsafe {
23 ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
24 s.assume_init()
25 }
26 }
27 }
28 #[repr(C)]
29 #[derive(Debug, Copy, Clone)]
30 pub struct Bar {
31 pub m_member: RefPtr<Foo>,
32 }
33 #[test]
bindgen_test_layout_Bar()34 fn bindgen_test_layout_Bar() {
35 const UNINIT: ::std::mem::MaybeUninit<Bar> =
36 ::std::mem::MaybeUninit::uninit();
37 let ptr = UNINIT.as_ptr();
38 assert_eq!(
39 ::std::mem::size_of::<Bar>(),
40 8usize,
41 concat!("Size of: ", stringify!(Bar))
42 );
43 assert_eq!(
44 ::std::mem::align_of::<Bar>(),
45 8usize,
46 concat!("Alignment of ", stringify!(Bar))
47 );
48 assert_eq!(
49 unsafe {
50 ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize
51 },
52 0usize,
53 concat!(
54 "Offset of field: ",
55 stringify!(Bar),
56 "::",
57 stringify!(m_member)
58 )
59 );
60 }
61 impl Default for Bar {
default() -> Self62 fn default() -> Self {
63 let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
64 unsafe {
65 ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
66 s.assume_init()
67 }
68 }
69 }
70 #[test]
__bindgen_test_layout_RefPtr_open0_Foo_close0_instantiation()71 fn __bindgen_test_layout_RefPtr_open0_Foo_close0_instantiation() {
72 assert_eq!(
73 ::std::mem::size_of::<RefPtr<Foo>>(),
74 8usize,
75 concat!("Size of template specialization: ", stringify!(RefPtr<Foo>))
76 );
77 assert_eq!(
78 ::std::mem::align_of::<RefPtr<Foo>>(),
79 8usize,
80 concat!(
81 "Alignment of template specialization: ",
82 stringify!(RefPtr<Foo>)
83 )
84 );
85 }
86