]> git.lizzy.rs Git - rust.git/blobdiff - src/libcore/ptr.rs
Deprecate offset_to; switch core&alloc to using offset_from instead
[rust.git] / src / libcore / ptr.rs
index 5a54de06b5ef2bf55cd99509d1233582a5996db4..c1e150e9fb909906e41d4b35835b64c4df4e8b47 100644 (file)
@@ -677,6 +677,7 @@ pub fn wrapping_offset(self, count: isize) -> *const T where T: Sized {
     ///
     /// ```
     /// #![feature(offset_to)]
+    /// #![allow(deprecated)]
     ///
     /// fn main() {
     ///     let a = [0; 5];
@@ -689,14 +690,15 @@ pub fn wrapping_offset(self, count: isize) -> *const T where T: Sized {
     /// }
     /// ```
     #[unstable(feature = "offset_to", issue = "41079")]
+    #[rustc_deprecated(since = "1.27.0", reason = "Replaced by `wrapping_offset_from`, with the \
+        opposite argument order.  If you're writing unsafe code, consider `offset_from`.")]
     #[inline]
     pub fn offset_to(self, other: *const T) -> Option<isize> where T: Sized {
         let size = mem::size_of::<T>();
         if size == 0 {
             None
         } else {
-            let diff = (other as isize).wrapping_sub(self as isize);
-            Some(diff / size as isize)
+            Some(other.wrapping_offset_from(self))
         }
     }
 
@@ -1442,6 +1444,7 @@ pub unsafe fn as_mut<'a>(self) -> Option<&'a mut T> {
     ///
     /// ```
     /// #![feature(offset_to)]
+    /// #![allow(deprecated)]
     ///
     /// fn main() {
     ///     let mut a = [0; 5];
@@ -1454,14 +1457,15 @@ pub unsafe fn as_mut<'a>(self) -> Option<&'a mut T> {
     /// }
     /// ```
     #[unstable(feature = "offset_to", issue = "41079")]
+    #[rustc_deprecated(since = "1.27.0", reason = "Replaced by `wrapping_offset_from`, with the \
+        opposite argument order.  If you're writing unsafe code, consider `offset_from`.")]
     #[inline]
     pub fn offset_to(self, other: *const T) -> Option<isize> where T: Sized {
         let size = mem::size_of::<T>();
         if size == 0 {
             None
         } else {
-            let diff = (other as isize).wrapping_sub(self as isize);
-            Some(diff / size as isize)
+            Some(other.wrapping_offset_from(self))
         }
     }