diff --git a/src/test/ui/consts/offset_from_ub.rs b/src/test/ui/consts/offset_from_ub.rs index c96d62cd9235..c9030915620a 100644 --- a/src/test/ui/consts/offset_from_ub.rs +++ b/src/test/ui/consts/offset_from_ub.rs @@ -39,4 +39,11 @@ pub const OFFSET_FROM_NULL: isize = { unsafe { ptr.offset_from(ptr) } }; +pub const DIFFERENT_INT: isize = { // offset_from with two different integers: like DIFFERENT_ALLOC + //~^ NOTE + let ptr1 = 8 as *const u8; + let ptr2 = 16 as *const u8; + unsafe { ptr2.offset_from(ptr1) } +}; + fn main() {} diff --git a/src/test/ui/consts/offset_from_ub.stderr b/src/test/ui/consts/offset_from_ub.stderr index 1015b9cf7fcc..1bd09034bfc9 100644 --- a/src/test/ui/consts/offset_from_ub.stderr +++ b/src/test/ui/consts/offset_from_ub.stderr @@ -75,5 +75,24 @@ LL | | unsafe { ptr.offset_from(ptr) } LL | | }; | |__- -error: aborting due to 4 previous errors +error: any use of this value will cause an error + --> $SRC_DIR/libcore/ptr/mod.rs:LL:COL + | +LL | intrinsics::ptr_offset_from(self, origin) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | a memory access tried to interpret some bytes as a pointer + | inside call to `std::ptr::::offset_from` at $DIR/offset_from_ub.rs:46:14 + | + ::: $DIR/offset_from_ub.rs:42:1 + | +LL | / pub const DIFFERENT_INT: isize = { // offset_from with two different integers: like DIFFERENT_ALLOC +LL | | +LL | | let ptr1 = 8 as *const u8; +LL | | let ptr2 = 16 as *const u8; +LL | | unsafe { ptr2.offset_from(ptr1) } +LL | | }; + | |__- + +error: aborting due to 5 previous errors