From bf9254a75e06f61ecd837e2f90ed0afc22ffdede Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Wed, 16 Sep 2015 15:25:51 +0200 Subject: [PATCH] Reuse cmp in totally ordered types Instead of manually defining it, `partial_cmp` can simply wrap the result of `cmp` for totally ordered types. --- src/libcore/cmp.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index dc550fc2173a..3344d7ea5d7f 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -471,9 +471,7 @@ mod impls { impl PartialOrd for $t { #[inline] fn partial_cmp(&self, other: &$t) -> Option { - if *self == *other { Some(Equal) } - else if *self < *other { Some(Less) } - else { Some(Greater) } + Some(self.cmp(other)) } #[inline] fn lt(&self, other: &$t) -> bool { (*self) < (*other) }