@@ -857,7 +857,7 @@ impl<T: ?Sized> NonNull<T> {
857
857
/// that their safety preconditions are met:
858
858
/// ```rust
859
859
/// # unsafe fn blah(ptr: std::ptr::NonNull<u32>, origin: std::ptr::NonNull<u32>, count: usize) -> bool { unsafe {
860
- /// ptr.sub_ptr (origin) == count
860
+ /// ptr.offset_from_unsigned (origin) == count
861
861
/// # &&
862
862
/// origin.add(count) == ptr
863
863
/// # &&
@@ -890,25 +890,25 @@ impl<T: ?Sized> NonNull<T> {
890
890
/// let ptr1: NonNull<u32> = NonNull::from(&a[1]);
891
891
/// let ptr2: NonNull<u32> = NonNull::from(&a[3]);
892
892
/// unsafe {
893
- /// assert_eq!(ptr2.sub_ptr (ptr1), 2);
893
+ /// assert_eq!(ptr2.offset_from_unsigned (ptr1), 2);
894
894
/// assert_eq!(ptr1.add(2), ptr2);
895
895
/// assert_eq!(ptr2.sub(2), ptr1);
896
- /// assert_eq!(ptr2.sub_ptr (ptr2), 0);
896
+ /// assert_eq!(ptr2.offset_from_unsigned (ptr2), 0);
897
897
/// }
898
898
///
899
899
/// // This would be incorrect, as the pointers are not correctly ordered:
900
- /// // ptr1.sub_ptr (ptr2)
900
+ /// // ptr1.offset_from_unsigned (ptr2)
901
901
/// ```
902
902
#[ inline]
903
903
#[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
904
904
#[ stable( feature = "ptr_sub_ptr" , since = "CURRENT_RUSTC_VERSION" ) ]
905
905
#[ rustc_const_stable( feature = "const_ptr_sub_ptr" , since = "CURRENT_RUSTC_VERSION" ) ]
906
- pub const unsafe fn sub_ptr ( self , subtracted : NonNull < T > ) -> usize
906
+ pub const unsafe fn offset_from_unsigned ( self , subtracted : NonNull < T > ) -> usize
907
907
where
908
908
T : Sized ,
909
909
{
910
910
// SAFETY: the caller must uphold the safety contract for `sub_ptr`.
911
- unsafe { self . as_ptr ( ) . sub_ptr ( subtracted. as_ptr ( ) ) }
911
+ unsafe { self . as_ptr ( ) . offset_from_unsigned ( subtracted. as_ptr ( ) ) }
912
912
}
913
913
914
914
/// Calculates the distance between two pointers within the same allocation, *where it's known that
@@ -925,9 +925,9 @@ impl<T: ?Sized> NonNull<T> {
925
925
#[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
926
926
#[ stable( feature = "ptr_sub_ptr" , since = "CURRENT_RUSTC_VERSION" ) ]
927
927
#[ rustc_const_stable( feature = "const_ptr_sub_ptr" , since = "CURRENT_RUSTC_VERSION" ) ]
928
- pub const unsafe fn byte_sub_ptr < U : ?Sized > ( self , origin : NonNull < U > ) -> usize {
928
+ pub const unsafe fn byte_offset_from_unsigned < U : ?Sized > ( self , origin : NonNull < U > ) -> usize {
929
929
// SAFETY: the caller must uphold the safety contract for `byte_sub_ptr`.
930
- unsafe { self . as_ptr ( ) . byte_sub_ptr ( origin. as_ptr ( ) ) }
930
+ unsafe { self . as_ptr ( ) . byte_offset_from_unsigned ( origin. as_ptr ( ) ) }
931
931
}
932
932
933
933
/// Reads the value from `self` without moving it. This leaves the
0 commit comments