@@ -677,6 +677,7 @@ impl<T: ?Sized> *const T {
677
677
///
678
678
/// ```
679
679
/// #![feature(offset_to)]
680
+ /// #![allow(deprecated)]
680
681
///
681
682
/// fn main() {
682
683
/// let a = [0; 5];
@@ -689,14 +690,15 @@ impl<T: ?Sized> *const T {
689
690
/// }
690
691
/// ```
691
692
#[ 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`.") ]
692
695
#[ inline]
693
696
pub fn offset_to ( self , other : * const T ) -> Option < isize > where T : Sized {
694
697
let size = mem:: size_of :: < T > ( ) ;
695
698
if size == 0 {
696
699
None
697
700
} 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 ) )
700
702
}
701
703
}
702
704
@@ -1442,6 +1444,7 @@ impl<T: ?Sized> *mut T {
1442
1444
///
1443
1445
/// ```
1444
1446
/// #![feature(offset_to)]
1447
+ /// #![allow(deprecated)]
1445
1448
///
1446
1449
/// fn main() {
1447
1450
/// let mut a = [0; 5];
@@ -1454,14 +1457,15 @@ impl<T: ?Sized> *mut T {
1454
1457
/// }
1455
1458
/// ```
1456
1459
#[ 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`.") ]
1457
1462
#[ inline]
1458
1463
pub fn offset_to ( self , other : * const T ) -> Option < isize > where T : Sized {
1459
1464
let size = mem:: size_of :: < T > ( ) ;
1460
1465
if size == 0 {
1461
1466
None
1462
1467
} 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 ) )
1465
1469
}
1466
1470
}
1467
1471
0 commit comments