@@ -445,59 +445,6 @@ impl<T: ?Sized> *const T {
445445 intrinsics:: ptr_guaranteed_ne ( self , other)
446446 }
447447
448- /// Calculates the distance between two pointers. The returned value is in
449- /// units of T: the distance in bytes is divided by `mem::size_of::<T>()`.
450- ///
451- /// If the address different between the two pointers is not a multiple of
452- /// `mem::size_of::<T>()` then the result of the division is rounded towards
453- /// zero.
454- ///
455- /// Though this method is safe for any two pointers, note that its result
456- /// will be mostly useless if the two pointers aren't into the same allocated
457- /// object, for example if they point to two different local variables.
458- ///
459- /// # Panics
460- ///
461- /// This function panics if `T` is a zero-sized type.
462- ///
463- /// # Examples
464- ///
465- /// Basic usage:
466- ///
467- /// ```
468- /// #![feature(ptr_wrapping_offset_from)]
469- ///
470- /// let a = [0; 5];
471- /// let ptr1: *const i32 = &a[1];
472- /// let ptr2: *const i32 = &a[3];
473- /// assert_eq!(ptr2.wrapping_offset_from(ptr1), 2);
474- /// assert_eq!(ptr1.wrapping_offset_from(ptr2), -2);
475- /// assert_eq!(ptr1.wrapping_offset(2), ptr2);
476- /// assert_eq!(ptr2.wrapping_offset(-2), ptr1);
477- ///
478- /// let ptr1: *const i32 = 3 as _;
479- /// let ptr2: *const i32 = 13 as _;
480- /// assert_eq!(ptr2.wrapping_offset_from(ptr1), 2);
481- /// ```
482- #[ unstable( feature = "ptr_wrapping_offset_from" , issue = "41079" ) ]
483- #[ rustc_deprecated(
484- since = "1.46.0" ,
485- reason = "Pointer distances across allocation \
486- boundaries are not typically meaningful. \
487- Use integer subtraction if you really need this."
488- ) ]
489- #[ inline]
490- pub fn wrapping_offset_from ( self , origin : * const T ) -> isize
491- where
492- T : Sized ,
493- {
494- let pointee_size = mem:: size_of :: < T > ( ) ;
495- assert ! ( 0 < pointee_size && pointee_size <= isize :: MAX as usize ) ;
496-
497- let d = isize:: wrapping_sub ( self as _ , origin as _ ) ;
498- d. wrapping_div ( pointee_size as _ )
499- }
500-
501448 /// Calculates the offset from a pointer (convenience for `.offset(count as isize)`).
502449 ///
503450 /// `count` is in units of T; e.g., a `count` of 3 represents a pointer
0 commit comments