3 #![feature(const_size_of_val, const_align_of_val)]
4 #![feature(const_size_of_val_raw, const_align_of_val_raw, layout_for_ptr)]
10 #[derive(Clone, Copy)]
22 const FOO: Foo = Foo(4);
23 const BAR: Bar = Bar { _x: 4, _y: 1, _z: 2 };
24 const UGH: Ugh = Ugh { _a: [0; 3] };
26 const SIZE_OF_FOO: usize = mem::size_of_val(&FOO);
27 const SIZE_OF_BAR: usize = mem::size_of_val(&BAR);
28 const SIZE_OF_UGH: usize = mem::size_of_val(&UGH);
30 const ALIGN_OF_FOO: usize = mem::align_of_val(&FOO);
31 const ALIGN_OF_BAR: usize = mem::align_of_val(&BAR);
32 const ALIGN_OF_UGH: usize = mem::align_of_val(&UGH);
34 const SIZE_OF_SLICE: usize = mem::size_of_val("foobar".as_bytes());
36 const SIZE_OF_DANGLING: usize = unsafe { mem::size_of_val_raw(0x100 as *const i32) };
37 const ALIGN_OF_DANGLING: usize = unsafe { mem::align_of_val_raw(0x100 as *const i16) };
40 assert_eq!(SIZE_OF_FOO, mem::size_of::<Foo>());
41 assert_eq!(SIZE_OF_BAR, mem::size_of::<Bar>());
42 assert_eq!(SIZE_OF_UGH, mem::size_of::<Ugh>());
44 assert_eq!(ALIGN_OF_FOO, mem::align_of::<Foo>());
45 assert_eq!(ALIGN_OF_BAR, mem::align_of::<Bar>());
46 assert_eq!(ALIGN_OF_UGH, mem::align_of::<Ugh>());
48 assert_eq!(SIZE_OF_DANGLING, mem::size_of::<i32>());
49 assert_eq!(ALIGN_OF_DANGLING, mem::align_of::<i16>());
51 assert_eq!(SIZE_OF_SLICE, "foobar".len());