2020-06-27 04:57:43 -05:00
|
|
|
#![feature(core_intrinsics, const_raw_ptr_comparison)]
|
2020-12-31 06:11:34 -06:00
|
|
|
#![feature(layout_for_ptr)]
|
2019-06-02 23:20:13 -05:00
|
|
|
|
2020-04-15 11:00:16 -05:00
|
|
|
use std::intrinsics;
|
2020-12-31 06:11:34 -06:00
|
|
|
use std::mem::{size_of, size_of_val, size_of_val_raw};
|
2016-05-09 22:01:12 -05:00
|
|
|
|
2020-04-15 11:00:16 -05:00
|
|
|
struct Bomb;
|
|
|
|
|
|
|
|
impl Drop for Bomb {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
eprintln!("BOOM!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-09 22:01:12 -05:00
|
|
|
fn main() {
|
|
|
|
assert_eq!(size_of::<Option<i32>>(), 8);
|
|
|
|
assert_eq!(size_of_val(&()), 0);
|
|
|
|
assert_eq!(size_of_val(&42), 4);
|
|
|
|
assert_eq!(size_of_val(&[] as &[i32]), 0);
|
|
|
|
assert_eq!(size_of_val(&[1, 2, 3] as &[i32]), 12);
|
2016-05-09 22:03:53 -05:00
|
|
|
assert_eq!(size_of_val("foobar"), 6);
|
2019-06-02 23:20:13 -05:00
|
|
|
|
2020-12-31 06:11:34 -06:00
|
|
|
unsafe { assert_eq!(size_of_val_raw(&[1] as &[i32] as *const [i32]), 4); }
|
|
|
|
unsafe { assert_eq!(size_of_val_raw(0x100 as *const i32), 4); }
|
|
|
|
|
2020-04-15 11:00:16 -05:00
|
|
|
assert_eq!(intrinsics::type_name::<Option<i32>>(), "core::option::Option<i32>");
|
|
|
|
|
|
|
|
assert_eq!(intrinsics::likely(false), false);
|
|
|
|
assert_eq!(intrinsics::unlikely(true), true);
|
|
|
|
|
2020-12-30 17:17:08 -06:00
|
|
|
intrinsics::forget(Bomb);
|
2020-05-23 09:30:50 -05:00
|
|
|
|
|
|
|
let _v = intrinsics::discriminant_value(&Some(()));
|
|
|
|
let _v = intrinsics::discriminant_value(&0);
|
|
|
|
let _v = intrinsics::discriminant_value(&true);
|
|
|
|
let _v = intrinsics::discriminant_value(&vec![1,2,3]);
|
2020-06-27 04:57:43 -05:00
|
|
|
|
|
|
|
let addr = &13 as *const i32;
|
|
|
|
let addr2 = (addr as usize).wrapping_add(usize::MAX).wrapping_add(1);
|
|
|
|
assert!(addr.guaranteed_eq(addr2 as *const _));
|
|
|
|
assert!(addr.guaranteed_ne(0x100 as *const _));
|
2016-05-09 22:01:12 -05:00
|
|
|
}
|