diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 5c61a1ed103..edd5f989797 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -93,7 +93,7 @@ use intrinsics; use option::Option; use option::Option::{Some, None}; -use cmp::{PartialEq, Eq, PartialOrd, Equiv}; +use cmp::{PartialEq, Eq, Ord, PartialOrd, Equiv}; use cmp::Ordering; use cmp::Ordering::{Less, Equal, Greater}; @@ -388,16 +388,23 @@ mod externfnpointers { } // Comparison for pointers +impl Ord for *const T { + #[inline] + fn cmp(&self, other: &*const T) -> Ordering { + if self < other { + Less + } else if self == other { + Equal + } else { + Greater + } + } +} + impl PartialOrd for *const T { #[inline] fn partial_cmp(&self, other: &*const T) -> Option { - if self < other { - Some(Less) - } else if self == other { - Some(Equal) - } else { - Some(Greater) - } + Some(self.cmp(other)) } #[inline] @@ -413,16 +420,23 @@ impl PartialOrd for *const T { fn ge(&self, other: &*const T) -> bool { *self >= *other } } +impl Ord for *mut T { + #[inline] + fn cmp(&self, other: &*mut T) -> Ordering { + if self < other { + Less + } else if self == other { + Equal + } else { + Greater + } + } +} + impl PartialOrd for *mut T { #[inline] fn partial_cmp(&self, other: &*mut T) -> Option { - if self < other { - Some(Less) - } else if self == other { - Some(Equal) - } else { - Some(Greater) - } + Some(self.cmp(other)) } #[inline]