@@ -677,6 +677,7 @@ impl<T: ?Sized> *const T {
677677 ///
678678 /// ```
679679 /// #![feature(offset_to)]
680+ /// #![allow(deprecated)]
680681 ///
681682 /// fn main() {
682683 /// let a = [0; 5];
@@ -689,14 +690,15 @@ impl<T: ?Sized> *const T {
689690 /// }
690691 /// ```
691692 #[ unstable( feature = "offset_to" , issue = "41079" ) ]
693+ #[ rustc_deprecated( since = "1.27.0" , reason = "Replaced by `wrapping_offset_from`, with the \
694+ opposite argument order. If you're writing unsafe code, consider `offset_from`.") ]
692695 #[ inline]
693696 pub fn offset_to ( self , other : * const T ) -> Option < isize > where T : Sized {
694697 let size = mem:: size_of :: < T > ( ) ;
695698 if size == 0 {
696699 None
697700 } else {
698- let diff = ( other as isize ) . wrapping_sub ( self as isize ) ;
699- Some ( diff / size as isize )
701+ Some ( other. wrapping_offset_from ( self ) )
700702 }
701703 }
702704
@@ -1442,6 +1444,7 @@ impl<T: ?Sized> *mut T {
14421444 ///
14431445 /// ```
14441446 /// #![feature(offset_to)]
1447+ /// #![allow(deprecated)]
14451448 ///
14461449 /// fn main() {
14471450 /// let mut a = [0; 5];
@@ -1454,14 +1457,15 @@ impl<T: ?Sized> *mut T {
14541457 /// }
14551458 /// ```
14561459 #[ unstable( feature = "offset_to" , issue = "41079" ) ]
1460+ #[ rustc_deprecated( since = "1.27.0" , reason = "Replaced by `wrapping_offset_from`, with the \
1461+ opposite argument order. If you're writing unsafe code, consider `offset_from`.") ]
14571462 #[ inline]
14581463 pub fn offset_to ( self , other : * const T ) -> Option < isize > where T : Sized {
14591464 let size = mem:: size_of :: < T > ( ) ;
14601465 if size == 0 {
14611466 None
14621467 } else {
1463- let diff = ( other as isize ) . wrapping_sub ( self as isize ) ;
1464- Some ( diff / size as isize )
1468+ Some ( other. wrapping_offset_from ( self ) )
14651469 }
14661470 }
14671471
0 commit comments