2 use core::intrinsics::assume;
5 fn test_typeid_sized_types() {
9 assert_eq!(TypeId::of::<X>(), TypeId::of::<X>());
10 assert_eq!(TypeId::of::<Y>(), TypeId::of::<Y>());
11 assert!(TypeId::of::<X>() != TypeId::of::<Y>());
15 fn test_typeid_unsized_types() {
18 struct Y(dyn Z + 'static);
20 assert_eq!(TypeId::of::<X>(), TypeId::of::<X>());
21 assert_eq!(TypeId::of::<Y>(), TypeId::of::<Y>());
22 assert!(TypeId::of::<X>() != TypeId::of::<Y>());
25 // Check that `const_assume` feature allow `assume` intrinsic
26 // to be used in const contexts.
28 fn test_assume_can_be_in_const_contexts() {
29 const unsafe fn foo(x: usize, y: usize) -> usize {
30 // SAFETY: the entire function is not safe,
31 // but it is just an example not used elsewhere.
32 unsafe { assume(y != 0) };
35 let rs = unsafe { foo(42, 97) };
40 #[cfg(not(bootstrap))]
41 const fn test_write_bytes_in_const_contexts() {
42 use core::intrinsics::write_bytes;
44 const TEST: [u32; 3] = {
45 let mut arr = [1u32, 2, 3];
47 write_bytes(arr.as_mut_ptr(), 0, 2);
52 assert!(TEST[0] == 0);
53 assert!(TEST[1] == 0);
54 assert!(TEST[2] == 3);
56 const TEST2: [u32; 3] = {
57 let mut arr = [1u32, 2, 3];
59 write_bytes(arr.as_mut_ptr(), 1, 2);
64 assert!(TEST2[0] == 16843009);
65 assert!(TEST2[1] == 16843009);
66 assert!(TEST2[2] == 3);
70 fn test_hints_in_const_contexts() {
71 use core::intrinsics::{likely, unlikely};
73 // In const contexts, they just return their argument.
75 assert!(true == likely(true));
76 assert!(false == likely(false));
77 assert!(true == unlikely(true));
78 assert!(false == unlikely(false));
79 assert!(42u32 == core::intrinsics::black_box(42u32));
80 assert!(42u32 == core::hint::black_box(42u32));
84 #[cfg(not(bootstrap))]
86 fn test_const_allocate_at_runtime() {
87 use core::intrinsics::const_allocate;
89 assert!(const_allocate(4, 4).is_null());
93 #[cfg(not(bootstrap))]
95 fn test_const_deallocate_at_runtime() {
96 use core::intrinsics::const_deallocate;
97 const X: &u32 = &42u32;
100 const_deallocate(X as *const _ as *mut u8, 4, 4); // nop
101 const_deallocate(x as *const _ as *mut u8, 4, 4); // nop
102 const_deallocate(core::ptr::null_mut(), 1, 1); // nop