blob: c4ef62a09cd4e9608f512c7757481e79714e3de3 [file] [log] [blame]
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]
/// This should get an `_address` byte.
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Empty {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Empty() {
assert_eq!(
::std::mem::size_of::<Empty>(),
1usize,
concat!("Size of: ", stringify!(Empty))
);
assert_eq!(
::std::mem::align_of::<Empty>(),
1usize,
concat!("Alignment of ", stringify!(Empty))
);
}
/// This should not get an `_address` byte, so `sizeof(Inherits)` should be
/// `1`.
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Inherits {
pub b: bool,
}
#[test]
fn bindgen_test_layout_Inherits() {
assert_eq!(
::std::mem::size_of::<Inherits>(),
1usize,
concat!("Size of: ", stringify!(Inherits))
);
assert_eq!(
::std::mem::align_of::<Inherits>(),
1usize,
concat!("Alignment of ", stringify!(Inherits))
);
assert_eq!(
{
let struct_instance = unsafe { std::mem::zeroed::<Inherits>() };
let struct_ptr = &struct_instance as *const Inherits;
let field_ptr = std::ptr::addr_of!(struct_instance.b);
let struct_address = struct_ptr as usize;
let field_address = field_ptr as usize;
std::mem::forget(struct_instance);
field_address.checked_sub(struct_address).unwrap()
},
0usize,
concat!(
"Offset of field: ",
stringify!(Inherits),
"::",
stringify!(b)
)
);
}
/// This should not get an `_address` byte, but contains `Empty` which *does* get
/// one, so `sizeof(Contains)` should be `1 + 1`.
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Contains {
pub empty: Empty,
pub b: bool,
}
#[test]
fn bindgen_test_layout_Contains() {
assert_eq!(
::std::mem::size_of::<Contains>(),
2usize,
concat!("Size of: ", stringify!(Contains))
);
assert_eq!(
::std::mem::align_of::<Contains>(),
1usize,
concat!("Alignment of ", stringify!(Contains))
);
assert_eq!(
{
let struct_instance = unsafe { std::mem::zeroed::<Contains>() };
let struct_ptr = &struct_instance as *const Contains;
let field_ptr = std::ptr::addr_of!(struct_instance.empty);
let struct_address = struct_ptr as usize;
let field_address = field_ptr as usize;
std::mem::forget(struct_instance);
field_address.checked_sub(struct_address).unwrap()
},
0usize,
concat!(
"Offset of field: ",
stringify!(Contains),
"::",
stringify!(empty)
)
);
assert_eq!(
{
let struct_instance = unsafe { std::mem::zeroed::<Contains>() };
let struct_ptr = &struct_instance as *const Contains;
let field_ptr = std::ptr::addr_of!(struct_instance.b);
let struct_address = struct_ptr as usize;
let field_address = field_ptr as usize;
std::mem::forget(struct_instance);
field_address.checked_sub(struct_address).unwrap()
},
1usize,
concat!(
"Offset of field: ",
stringify!(Contains),
"::",
stringify!(b)
)
);
}