Skip to content

Commit

Permalink
rollup merge of rust-lang#19779: Noctune/master
Browse files Browse the repository at this point in the history
The old PartialOrd impl for raw pointers would always return Some(_), so It might as well implement Ord too.
  • Loading branch information
brson committed Dec 12, 2014
2 parents b71d2bd + 3cc730e commit d9af23d
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -388,17 +388,24 @@ mod externfnpointers {
}

// Comparison for pointers
impl<T> PartialOrd for *const T {
impl<T> Ord for *const T {
#[inline]
fn partial_cmp(&self, other: &*const T) -> Option<Ordering> {
fn cmp(&self, other: &*const T) -> Ordering {
if self < other {
Some(Less)
Less
} else if self == other {
Some(Equal)
Equal
} else {
Some(Greater)
Greater
}
}
}

impl<T> PartialOrd for *const T {
#[inline]
fn partial_cmp(&self, other: &*const T) -> Option<Ordering> {
Some(self.cmp(other))
}

#[inline]
fn lt(&self, other: &*const T) -> bool { *self < *other }
Expand All @@ -413,17 +420,24 @@ impl<T> PartialOrd for *const T {
fn ge(&self, other: &*const T) -> bool { *self >= *other }
}

impl<T> PartialOrd for *mut T {
impl<T> Ord for *mut T {
#[inline]
fn partial_cmp(&self, other: &*mut T) -> Option<Ordering> {
fn cmp(&self, other: &*mut T) -> Ordering {
if self < other {
Some(Less)
Less
} else if self == other {
Some(Equal)
Equal
} else {
Some(Greater)
Greater
}
}
}

impl<T> PartialOrd for *mut T {
#[inline]
fn partial_cmp(&self, other: &*mut T) -> Option<Ordering> {
Some(self.cmp(other))
}

#[inline]
fn lt(&self, other: &*mut T) -> bool { *self < *other }
Expand Down

0 comments on commit d9af23d

Please sign in to comment.