error[E0080]: evaluation of constant value failed --> $DIR/offset_from_ub.rs:18:27 | LL | let offset = unsafe { ptr_offset_from(field_ptr, base_ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ptr_offset_from cannot compute offset of pointers into different allocations. error: any use of this value will cause an error --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL | LL | unsafe { intrinsics::ptr_offset_from(self, origin) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | unable to turn bytes into a pointer | inside `ptr::const_ptr::::offset_from` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL | inside `NOT_PTR` at $DIR/offset_from_ub.rs:24:14 | ::: $DIR/offset_from_ub.rs:23:1 | LL | / pub const NOT_PTR: usize = { LL | | unsafe { (42 as *const u8).offset_from(&5u8) as usize } LL | | }; | |__- | = note: `#[deny(const_err)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #71800 error[E0080]: evaluation of constant value failed --> $DIR/offset_from_ub.rs:31:14 | LL | unsafe { ptr_offset_from(field_ptr, base_ptr as *const u16) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ exact_div: 1_isize cannot be divided by 2_isize without remainder error[E0080]: evaluation of constant value failed --> $DIR/offset_from_ub.rs:37:14 | LL | unsafe { ptr_offset_from(ptr, ptr) } | ^^^^^^^^^^^^^^^^^^^^^^^^^ null pointer is not a valid pointer for this operation error: any use of this value will cause an error --> $DIR/offset_from_ub.rs:44:14 | LL | / pub const DIFFERENT_INT: isize = { // offset_from with two different integers: like DIFFERENT_ALLOC LL | | let ptr1 = 8 as *const u8; LL | | let ptr2 = 16 as *const u8; LL | | unsafe { ptr_offset_from(ptr2, ptr1) } | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn bytes into a pointer LL | | LL | | }; | |__- | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #71800 error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0080`.