1 // ignore-x86 FIXME: missing sysroot spans (#53081)
3 #![feature(const_raw_ptr_deref)]
4 #![feature(const_ptr_offset_from)]
5 #![feature(ptr_offset_from)]
13 pub const DIFFERENT_ALLOC
: usize = {
15 let uninit
= std
::mem
::MaybeUninit
::<Struct
>::uninit();
16 let base_ptr
: *const Struct
= &uninit
as *const _
as *const Struct
;
17 let uninit2
= std
::mem
::MaybeUninit
::<Struct
>::uninit();
18 let field_ptr
: *const Struct
= &uninit2
as *const _
as *const Struct
;
19 let offset
= unsafe { field_ptr.offset_from(base_ptr) }
;
23 pub const NOT_PTR
: usize = {
25 unsafe { (42 as *const u8).offset_from(&5u8) as usize }
28 pub const NOT_MULTIPLE_OF_SIZE
: isize = {
30 let data
= [5u8, 6, 7];
31 let base_ptr
= data
.as_ptr();
32 let field_ptr
= &data
[1] as *const u8 as *const u16;
33 unsafe { field_ptr.offset_from(base_ptr as *const u16) }
36 pub const OFFSET_FROM_NULL
: isize = {
38 let ptr
= 0 as *const u8;
39 unsafe { ptr.offset_from(ptr) }
42 pub const DIFFERENT_INT
: isize = { // offset_from with two different integers: like DIFFERENT_ALLOC
44 let ptr1
= 8 as *const u8;
45 let ptr2
= 16 as *const u8;
46 unsafe { ptr2.offset_from(ptr1) }