]> git.lizzy.rs Git - rust.git/blobdiff - src/libcore/ptr.rs
Merge pull request #20674 from jbcrail/fix-misspelled-comments
[rust.git] / src / libcore / ptr.rs
index 75bb8d33ea85f514419190b2d52be05d579d8f51..20305c3191a098f24f73e1503f7e3a68595b4208 100644 (file)
 use mem;
 use clone::Clone;
 use intrinsics;
-use option::Option::{mod, Some, None};
-use kinds::{Send, Sync};
+use option::Option::{self, Some, None};
+use marker::{Send, Sized, Sync};
 
-use cmp::{PartialEq, Eq, Ord, PartialOrd, Equiv};
-use cmp::Ordering::{mod, Less, Equal, Greater};
+use cmp::{PartialEq, Eq, Ord, PartialOrd};
+use cmp::Ordering::{self, Less, Equal, Greater};
 
-// FIXME #19649: instrinsic docs don't render, so these have no docs :(
+// FIXME #19649: intrinsic docs don't render, so these have no docs :(
 
 #[unstable]
 pub use intrinsics::copy_nonoverlapping_memory;
@@ -233,7 +233,7 @@ pub unsafe fn read_and_zero<T>(dest: *mut T) -> T {
 /// not drop the contents of `dst`. This could leak allocations or resources,
 /// so care must be taken not to overwrite an object that should be dropped.
 ///
-/// This is appropriate for initializing uninitialized memory, or overwritting
+/// This is appropriate for initializing uninitialized memory, or overwriting
 /// memory that has previously been `read` from.
 #[inline]
 #[stable]
@@ -243,23 +243,13 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
 
 /// Methods on raw pointers
 #[stable]
-pub trait PtrExt<T> {
-    /// Returns the null pointer.
-    #[deprecated = "call ptr::null instead"]
-    fn null() -> Self;
+pub trait PtrExt: Sized {
+    type Target;
 
     /// Returns true if the pointer is null.
     #[stable]
     fn is_null(self) -> bool;
 
-    /// Returns true if the pointer is not equal to the null pointer.
-    #[deprecated = "use !p.is_null() instead"]
-    fn is_not_null(self) -> bool { !self.is_null() }
-
-    /// Returns true if the pointer is not null.
-    #[deprecated = "use `as uint` instead"]
-    fn to_uint(self) -> uint;
-
     /// Returns `None` if the pointer is null, or else returns a reference to
     /// the value wrapped in `Some`.
     ///
@@ -271,7 +261,7 @@ fn is_not_null(self) -> bool { !self.is_null() }
     /// memory.
     #[unstable = "Option is not clearly the right return type, and we may want \
                   to tie the return lifetime to a borrow of the raw pointer"]
-    unsafe fn as_ref<'a>(&self) -> Option<&'a T>;
+    unsafe fn as_ref<'a>(&self) -> Option<&'a Self::Target>;
 
     /// Calculates the offset from a pointer. `count` is in units of T; e.g. a
     /// `count` of 3 represents a pointer offset of `3 * sizeof::<T>()` bytes.
@@ -287,7 +277,9 @@ fn is_not_null(self) -> bool { !self.is_null() }
 
 /// Methods on mutable raw pointers
 #[stable]
-pub trait MutPtrExt<T>{
+pub trait MutPtrExt {
+    type Target;
+
     /// Returns `None` if the pointer is null, or else returns a mutable
     /// reference to the value wrapped in `Some`.
     ///
@@ -297,23 +289,17 @@ pub trait MutPtrExt<T>{
     /// of the returned pointer.
     #[unstable = "Option is not clearly the right return type, and we may want \
                   to tie the return lifetime to a borrow of the raw pointer"]
-    unsafe fn as_mut<'a>(&self) -> Option<&'a mut T>;
+    unsafe fn as_mut<'a>(&self) -> Option<&'a mut Self::Target>;
 }
 
 #[stable]
-impl<T> PtrExt<T> for *const T {
-    #[inline]
-    #[deprecated = "call ptr::null instead"]
-    fn null() -> *const T { null() }
+impl<T> PtrExt for *const T {
+    type Target = T;
 
     #[inline]
     #[stable]
     fn is_null(self) -> bool { self as uint == 0 }
 
-    #[inline]
-    #[deprecated = "use `as uint` instead"]
-    fn to_uint(self) -> uint { self as uint }
-
     #[inline]
     #[stable]
     unsafe fn offset(self, count: int) -> *const T {
@@ -333,19 +319,13 @@ unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
 }
 
 #[stable]
-impl<T> PtrExt<T> for *mut T {
-    #[inline]
-    #[deprecated = "call ptr::null instead"]
-    fn null() -> *mut T { null_mut() }
+impl<T> PtrExt for *mut T {
+    type Target = T;
 
     #[inline]
     #[stable]
     fn is_null(self) -> bool { self as uint == 0 }
 
-    #[inline]
-    #[deprecated = "use `as uint` instead"]
-    fn to_uint(self) -> uint { self as uint }
-
     #[inline]
     #[stable]
     unsafe fn offset(self, count: int) -> *mut T {
@@ -365,7 +345,9 @@ unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
 }
 
 #[stable]
-impl<T> MutPtrExt<T> for *mut T {
+impl<T> MutPtrExt for *mut T {
+    type Target = T;
+
     #[inline]
     #[unstable = "return value does not necessarily convey all possible \
                   information"]
@@ -379,6 +361,7 @@ unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> {
 }
 
 // Equality for pointers
+#[stable]
 impl<T> PartialEq for *const T {
     #[inline]
     fn eq(&self, other: &*const T) -> bool {
@@ -388,8 +371,10 @@ fn eq(&self, other: &*const T) -> bool {
     fn ne(&self, other: &*const T) -> bool { !self.eq(other) }
 }
 
+#[stable]
 impl<T> Eq for *const T {}
 
+#[stable]
 impl<T> PartialEq for *mut T {
     #[inline]
     fn eq(&self, other: &*mut T) -> bool {
@@ -399,25 +384,9 @@ fn eq(&self, other: &*mut T) -> bool {
     fn ne(&self, other: &*mut T) -> bool { !self.eq(other) }
 }
 
+#[stable]
 impl<T> Eq for *mut T {}
 
-// Equivalence for pointers
-#[allow(deprecated)]
-#[deprecated = "Use overloaded `core::cmp::PartialEq`"]
-impl<T> Equiv<*mut T> for *const T {
-    fn equiv(&self, other: &*mut T) -> bool {
-        self.to_uint() == other.to_uint()
-    }
-}
-
-#[allow(deprecated)]
-#[deprecated = "Use overloaded `core::cmp::PartialEq`"]
-impl<T> Equiv<*const T> for *mut T {
-    fn equiv(&self, other: &*const T) -> bool {
-        self.to_uint() == other.to_uint()
-    }
-}
-
 #[stable]
 impl<T> Clone for *const T {
     #[inline]
@@ -439,6 +408,7 @@ mod externfnpointers {
     use mem;
     use cmp::PartialEq;
 
+    #[stable]
     impl<_R> PartialEq for extern "C" fn() -> _R {
         #[inline]
         fn eq(&self, other: &extern "C" fn() -> _R) -> bool {
@@ -449,6 +419,7 @@ fn eq(&self, other: &extern "C" fn() -> _R) -> bool {
     }
     macro_rules! fnptreq {
         ($($p:ident),*) => {
+            #[stable]
             impl<_R,$($p),*> PartialEq for extern "C" fn($($p),*) -> _R {
                 #[inline]
                 fn eq(&self, other: &extern "C" fn($($p),*) -> _R) -> bool {
@@ -468,6 +439,7 @@ fn eq(&self, other: &extern "C" fn($($p),*) -> _R) -> bool {
 }
 
 // Comparison for pointers
+#[stable]
 impl<T> Ord for *const T {
     #[inline]
     fn cmp(&self, other: &*const T) -> Ordering {
@@ -481,6 +453,7 @@ fn cmp(&self, other: &*const T) -> Ordering {
     }
 }
 
+#[stable]
 impl<T> PartialOrd for *const T {
     #[inline]
     fn partial_cmp(&self, other: &*const T) -> Option<Ordering> {
@@ -500,6 +473,7 @@ fn gt(&self, other: &*const T) -> bool { *self > *other }
     fn ge(&self, other: &*const T) -> bool { *self >= *other }
 }
 
+#[stable]
 impl<T> Ord for *mut T {
     #[inline]
     fn cmp(&self, other: &*mut T) -> Ordering {
@@ -513,6 +487,7 @@ fn cmp(&self, other: &*mut T) -> Ordering {
     }
 }
 
+#[stable]
 impl<T> PartialOrd for *mut T {
     #[inline]
     fn partial_cmp(&self, other: &*mut T) -> Option<Ordering> {