Rollup merge of #137483 - bend-n:😅, r=Noratrieb
rename sub_ptr to offset_from_unsigned i also made `byte_sub_ptr` `byte_offset_from_unsigned` fixes #137121 tracking issue #95892
This commit is contained in:
commit
18ffee2126
18 changed files with 51 additions and 51 deletions
|
|
@ -3,5 +3,5 @@ fn main() {
|
|||
let arr = [0u8; 8];
|
||||
let ptr1 = arr.as_ptr();
|
||||
let ptr2 = ptr1.wrapping_add(4);
|
||||
let _val = unsafe { ptr1.sub_ptr(ptr2) }; //~ERROR: first pointer has smaller address than second
|
||||
let _val = unsafe { ptr1.offset_from_unsigned(ptr2) }; //~ERROR: first pointer has smaller address than second
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
error: Undefined Behavior: `ptr_offset_from_unsigned` called when first pointer has smaller address than second: $ADDR < $ADDR
|
||||
--> tests/fail/intrinsics/ptr_offset_from_unsigned_neg.rs:LL:CC
|
||||
|
|
||||
LL | let _val = unsafe { ptr1.sub_ptr(ptr2) };
|
||||
| ^^^^^^^^^^^^^^^^^^ `ptr_offset_from_unsigned` called when first pointer has smaller address than second: $ADDR < $ADDR
|
||||
LL | let _val = unsafe { ptr1.offset_from_unsigned(ptr2) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from_unsigned` called when first pointer has smaller address than second: $ADDR < $ADDR
|
||||
|
|
||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ fn smoke() {
|
|||
let _val = ptr.wrapping_sub(0);
|
||||
let _val = unsafe { ptr.sub(0) };
|
||||
let _val = unsafe { ptr.offset_from(ptr) };
|
||||
let _val = unsafe { ptr.sub_ptr(ptr) };
|
||||
let _val = unsafe { ptr.offset_from_unsigned(ptr) };
|
||||
}
|
||||
|
||||
fn test_offset_from() {
|
||||
|
|
@ -32,14 +32,14 @@ fn test_offset_from() {
|
|||
let y = x.offset(12);
|
||||
|
||||
assert_eq!(y.offset_from(x), 12);
|
||||
assert_eq!(y.sub_ptr(x), 12);
|
||||
assert_eq!(y.offset_from_unsigned(x), 12);
|
||||
assert_eq!(x.offset_from(y), -12);
|
||||
assert_eq!((y as *const u32).offset_from(x as *const u32), 12 / 4);
|
||||
assert_eq!((x as *const u32).offset_from(y as *const u32), -12 / 4);
|
||||
|
||||
let x = (((x as usize) * 2) / 2) as *const u8;
|
||||
assert_eq!(y.offset_from(x), 12);
|
||||
assert_eq!(y.sub_ptr(x), 12);
|
||||
assert_eq!(y.offset_from_unsigned(x), 12);
|
||||
assert_eq!(x.offset_from(y), -12);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue