File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -39,4 +39,11 @@ pub const OFFSET_FROM_NULL: isize = {
39
39
unsafe { ptr. offset_from ( ptr) }
40
40
} ;
41
41
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
+
42
49
fn main ( ) { }
Original file line number Diff line number Diff line change @@ -75,5 +75,24 @@ LL | | unsafe { ptr.offset_from(ptr) }
75
75
LL | | };
76
76
| |__-
77
77
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
79
98
You can’t perform that action at this time.
0 commit comments