Skip to content

Add Ord impl to raw pointers #19779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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