Skip to content

Commit d9af23d

Browse files
committed
rollup merge of rust-lang#19779: Noctune/master
The old PartialOrd impl for raw pointers would always return Some(_), so It might as well implement Ord too.
2 parents b71d2bd + 3cc730e commit d9af23d

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/libcore/ptr.rs

+25-11
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ use intrinsics;
9393
use option::Option;
9494
use option::Option::{Some, None};
9595

96-
use cmp::{PartialEq, Eq, PartialOrd, Equiv};
96+
use cmp::{PartialEq, Eq, Ord, PartialOrd, Equiv};
9797
use cmp::Ordering;
9898
use cmp::Ordering::{Less, Equal, Greater};
9999

@@ -388,17 +388,24 @@ mod externfnpointers {
388388
}
389389

390390
// Comparison for pointers
391-
impl<T> PartialOrd for *const T {
391+
impl<T> Ord for *const T {
392392
#[inline]
393-
fn partial_cmp(&self, other: &*const T) -> Option<Ordering> {
393+
fn cmp(&self, other: &*const T) -> Ordering {
394394
if self < other {
395-
Some(Less)
395+
Less
396396
} else if self == other {
397-
Some(Equal)
397+
Equal
398398
} else {
399-
Some(Greater)
399+
Greater
400400
}
401401
}
402+
}
403+
404+
impl<T> PartialOrd for *const T {
405+
#[inline]
406+
fn partial_cmp(&self, other: &*const T) -> Option<Ordering> {
407+
Some(self.cmp(other))
408+
}
402409

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

416-
impl<T> PartialOrd for *mut T {
423+
impl<T> Ord for *mut T {
417424
#[inline]
418-
fn partial_cmp(&self, other: &*mut T) -> Option<Ordering> {
425+
fn cmp(&self, other: &*mut T) -> Ordering {
419426
if self < other {
420-
Some(Less)
427+
Less
421428
} else if self == other {
422-
Some(Equal)
429+
Equal
423430
} else {
424-
Some(Greater)
431+
Greater
425432
}
426433
}
434+
}
435+
436+
impl<T> PartialOrd for *mut T {
437+
#[inline]
438+
fn partial_cmp(&self, other: &*mut T) -> Option<Ordering> {
439+
Some(self.cmp(other))
440+
}
427441

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

0 commit comments

Comments
 (0)