Skip to content

Commit 21d284b

Browse files
committed
also test different integers
1 parent 3c944fe commit 21d284b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/test/ui/consts/offset_from_ub.rs

+7
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,11 @@ pub const OFFSET_FROM_NULL: isize = {
3939
unsafe { ptr.offset_from(ptr) }
4040
};
4141

42+
pub const DIFFERENT_INT: isize = { // offset_from with two different integers: like DIFFERENT_ALLOC
43+
//~^ NOTE
44+
let ptr1 = 8 as *const u8;
45+
let ptr2 = 16 as *const u8;
46+
unsafe { ptr2.offset_from(ptr1) }
47+
};
48+
4249
fn main() {}

src/test/ui/consts/offset_from_ub.stderr

+20-1
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,24 @@ LL | | unsafe { ptr.offset_from(ptr) }
7575
LL | | };
7676
| |__-
7777

78-
error: aborting due to 4 previous errors
78+
error: any use of this value will cause an error
79+
--> $SRC_DIR/libcore/ptr/mod.rs:LL:COL
80+
|
81+
LL | intrinsics::ptr_offset_from(self, origin)
82+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
83+
| |
84+
| a memory access tried to interpret some bytes as a pointer
85+
| inside call to `std::ptr::<impl *const u8>::offset_from` at $DIR/offset_from_ub.rs:46:14
86+
|
87+
::: $DIR/offset_from_ub.rs:42:1
88+
|
89+
LL | / pub const DIFFERENT_INT: isize = { // offset_from with two different integers: like DIFFERENT_ALLOC
90+
LL | |
91+
LL | | let ptr1 = 8 as *const u8;
92+
LL | | let ptr2 = 16 as *const u8;
93+
LL | | unsafe { ptr2.offset_from(ptr1) }
94+
LL | | };
95+
| |__-
96+
97+
error: aborting due to 5 previous errors
7998

0 commit comments

Comments
 (0)