2019-06-02 23:20:13 -05:00
|
|
|
#![feature(core_intrinsics)]
|
|
|
|
|
2020-04-15 11:00:16 -05:00
|
|
|
use std::intrinsics;
|
2016-05-09 22:01:12 -05:00
|
|
|
use std::mem::{size_of, size_of_val};
|
|
|
|
|
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-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);
|
|
|
|
|
|
|
|
unsafe { intrinsics::forget(Bomb); }
|
2016-05-09 22:01:12 -05:00
|
|
|
}
|