about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-13 06:01:31 -0700
committerbors <bors@rust-lang.org>2013-07-13 06:01:31 -0700
commit403cdd84a4e9f01848445255078cce6bcebae8e3 (patch)
tree36e91c61a895424f6ad72f061316ad82f6d64c63 /src/libstd
parenta9eb86823049c2eff98e74fcac8ae75cc8760f33 (diff)
parent36f20423c31601c7b2e4f94368e79f44146cb064 (diff)
downloadrust-403cdd84a4e9f01848445255078cce6bcebae8e3.tar.gz
rust-403cdd84a4e9f01848445255078cce6bcebae8e3.zip
auto merge of #7765 : blake2-ppc/rust/ord-default-methods, r=huonw
Rust will allow to supply default methods for all four methods, but we
don't have any nice error reporting for the case where at least one
method must be implemented, but it's arbitrary which.

So in this case, we require `lt`, but allow implementing the others if needed.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/cmp.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/libstd/cmp.rs b/src/libstd/cmp.rs
index 2c4bb46b23b..77d4e945aae 100644
--- a/src/libstd/cmp.rs
+++ b/src/libstd/cmp.rs
@@ -157,19 +157,20 @@ pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering {
 /**
 * Trait for values that can be compared for a sort-order.
 *
-* Eventually this may be simplified to only require
-* an `le` method, with the others generated from
-* default implementations. However it should remain
-* possible to implement the others separately, for
-* compatibility with floating-point NaN semantics
+* Ord only requires implementation of the `lt` method,
+* with the others generated from default implementations.
+*
+* However it remains possible to implement the others separately,
+* for compatibility with floating-point NaN semantics
 * (cf. IEEE 754-2008 section 5.11).
 */
+#[allow(default_methods)] // NOTE: Remove when allowed in stage0
 #[lang="ord"]
 pub trait Ord {
     fn lt(&self, other: &Self) -> bool;
-    fn le(&self, other: &Self) -> bool;
-    fn ge(&self, other: &Self) -> bool;
-    fn gt(&self, other: &Self) -> bool;
+    fn le(&self, other: &Self) -> bool { !other.lt(self) }
+    fn gt(&self, other: &Self) -> bool {  other.lt(self) }
+    fn ge(&self, other: &Self) -> bool { !self.lt(other) }
 }
 
 /// The equivalence relation. Two values may be equivalent even if they are