@@ -798,8 +798,20 @@ impl<T: ?Sized> *mut T {
798798 /// but it provides slightly more information to the optimizer, which can
799799 /// sometimes allow it to optimize slightly better with some backends.
800800 ///
801- /// This method is the inverse of [`add`](#method.add) (and, with the parameters
802- /// in the other order, of [`sub`](#method.sub)).
801+ /// This method can be though of as recovering the `count` that was passed
802+ /// to [`add`](#method.add) (or, with the parameters in the other order,
803+ /// to [`sub`](#method.sub)). The following are all equivalent, assuming
804+ /// that their safety preconditions are met:
805+ /// ```rust
806+ /// # #![feature(ptr_unsigned_offset_from)]
807+ /// # unsafe fn blah(ptr: *mut i32, origin: *mut i32, count: usize) -> bool {
808+ /// ptr.sub_ptr(origin) == count
809+ /// # &&
810+ /// origin.add(count) == ptr
811+ /// # &&
812+ /// ptr.sub(count) == origin
813+ /// # }
814+ /// ```
803815 ///
804816 /// # Safety
805817 ///
@@ -828,23 +840,23 @@ impl<T: ?Sized> *mut T {
828840 /// let ptr1: *mut i32 = p.add(1);
829841 /// let ptr2: *mut i32 = p.add(3);
830842 ///
831- /// assert_eq!(ptr2.unsigned_offset_from (ptr1), 2);
843+ /// assert_eq!(ptr2.sub_ptr (ptr1), 2);
832844 /// assert_eq!(ptr1.add(2), ptr2);
833845 /// assert_eq!(ptr2.sub(2), ptr1);
834- /// assert_eq!(ptr2.unsigned_offset_from (ptr2), 0);
846+ /// assert_eq!(ptr2.sub_ptr (ptr2), 0);
835847 /// }
836848 ///
837849 /// // This would be incorrect, as the pointers are not correctly ordered:
838850 /// // ptr1.offset_from(ptr2)
839851 #[ unstable( feature = "ptr_unsigned_offset_from" , issue = "88888888" ) ]
840852 #[ rustc_const_unstable( feature = "const_ptr_offset_from" , issue = "92980" ) ]
841853 #[ inline]
842- pub const unsafe fn unsigned_offset_from ( self , origin : * const T ) -> usize
854+ pub const unsafe fn sub_ptr ( self , origin : * const T ) -> usize
843855 where
844856 T : Sized ,
845857 {
846- // SAFETY: the caller must uphold the safety contract for `unsigned_offset_from `.
847- unsafe { ( self as * const T ) . unsigned_offset_from ( origin) }
858+ // SAFETY: the caller must uphold the safety contract for `sub_ptr `.
859+ unsafe { ( self as * const T ) . sub_ptr ( origin) }
848860 }
849861
850862 /// Calculates the offset from a pointer (convenience for `.offset(count as isize)`).
0 commit comments