From 4d7d101a76deea69e9078d9ed6bb93ecca70e52a Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 24 Feb 2014 08:11:00 -0500 Subject: [PATCH] create a sensible comparison trait hierarchy * `Ord` inherits from `Eq` * `TotalOrd` inherits from `TotalEq` * `TotalOrd` inherits from `Ord` * `TotalEq` inherits from `Eq` This is a partial implementation of #12517. --- src/libcollections/btree.rs | 71 +++++++++++++++++++ src/libcollections/dlist.rs | 2 +- src/libextra/workcache.rs | 2 +- src/librustc/back/link.rs | 2 +- src/librustc/driver/session.rs | 2 +- src/librustc/middle/const_eval.rs | 2 +- src/librustc/middle/ty.rs | 4 +- src/libstd/cmp.rs | 14 ++-- src/libstd/iter.rs | 16 +++-- src/libstd/option.rs | 2 +- src/libstd/vec.rs | 4 +- src/libstd/vec_ng.rs | 15 ++-- src/libsyntax/ast.rs | 4 +- src/test/bench/shootout-k-nucleotide.rs | 2 +- .../deriving-span-Ord-enum-struct-variant.rs | 4 +- .../compile-fail/deriving-span-Ord-enum.rs | 4 +- .../compile-fail/deriving-span-Ord-struct.rs | 4 +- .../deriving-span-Ord-tuple-struct.rs | 4 +- ...riving-span-TotalEq-enum-struct-variant.rs | 4 +- .../deriving-span-TotalEq-enum.rs | 4 +- .../deriving-span-TotalEq-struct.rs | 4 +- .../deriving-span-TotalEq-tuple-struct.rs | 4 +- ...iving-span-TotalOrd-enum-struct-variant.rs | 4 +- .../deriving-span-TotalOrd-enum.rs | 4 +- .../deriving-span-TotalOrd-struct.rs | 4 +- .../deriving-span-TotalOrd-tuple-struct.rs | 4 +- src/test/compile-fail/issue-3344.rs | 1 + src/test/run-pass/cmp-default.rs | 16 +++++ src/test/run-pass/vector-sort-failure-safe.rs | 2 +- 29 files changed, 156 insertions(+), 53 deletions(-) diff --git a/src/libcollections/btree.rs b/src/libcollections/btree.rs index 171203b00b8..6411b6bc974 100644 --- a/src/libcollections/btree.rs +++ b/src/libcollections/btree.rs @@ -92,6 +92,11 @@ fn clone(&self) -> BTree { } } +impl Eq for BTree { + fn eq(&self, other: &BTree) -> bool { + self.equals(other) + } +} impl TotalEq for BTree { ///Testing equality on BTrees by comparing the root. @@ -100,6 +105,12 @@ fn equals(&self, other: &BTree) -> bool { } } +impl Ord for BTree { + fn lt(&self, other: &BTree) -> bool { + self.cmp(other) == Less + } +} + impl TotalOrd for BTree { ///Returns an ordering based on the root nodes of each BTree. fn cmp(&self, other: &BTree) -> Ordering { @@ -191,6 +202,12 @@ fn clone(&self) -> Node { } } +impl Eq for Node { + fn eq(&self, other: &Node) -> bool { + self.equals(other) + } +} + impl TotalEq for Node { ///Returns whether two nodes are equal based on the keys of each element. ///Two nodes are equal if all of their keys are the same. @@ -215,6 +232,12 @@ fn equals(&self, other: &Node) -> bool{ } } +impl Ord for Node { + fn lt(&self, other: &Node) -> bool { + self.cmp(other) == Less + } +} + impl TotalOrd for Node { ///Implementation of TotalOrd for Nodes. fn cmp(&self, other: &Node) -> Ordering { @@ -380,6 +403,12 @@ fn clone(&self) -> Leaf { } } +impl Eq for Leaf { + fn eq(&self, other: &Leaf) -> bool { + self.equals(other) + } +} + impl TotalEq for Leaf { ///Implementation of equals function for leaves that compares LeafElts. fn equals(&self, other: &Leaf) -> bool { @@ -387,6 +416,12 @@ fn equals(&self, other: &Leaf) -> bool { } } +impl Ord for Leaf { + fn lt(&self, other: &Leaf) -> bool { + self.cmp(other) == Less + } +} + impl TotalOrd for Leaf { ///Returns an ordering based on the first element of each Leaf. fn cmp(&self, other: &Leaf) -> Ordering { @@ -602,6 +637,12 @@ fn clone(&self) -> Branch { } } +impl Eq for Branch { + fn eq(&self, other: &Branch) -> bool { + self.equals(other) + } +} + impl TotalEq for Branch { ///Equals function for Branches--compares all the elements in each branch fn equals(&self, other: &Branch) -> bool { @@ -609,6 +650,12 @@ fn equals(&self, other: &Branch) -> bool { } } +impl Ord for Branch { + fn lt(&self, other: &Branch) -> bool { + self.cmp(other) == Less + } +} + impl TotalOrd for Branch { ///Compares the first elements of two branches to determine an ordering fn cmp(&self, other: &Branch) -> Ordering { @@ -663,6 +710,12 @@ fn clone(&self) -> LeafElt { } } +impl Eq for LeafElt { + fn eq(&self, other: &LeafElt) -> bool { + self.equals(other) + } +} + impl TotalEq for LeafElt { ///TotalEq for LeafElts fn equals(&self, other: &LeafElt) -> bool { @@ -670,6 +723,12 @@ fn equals(&self, other: &LeafElt) -> bool { } } +impl Ord for LeafElt { + fn lt(&self, other: &LeafElt) -> bool { + self.cmp(other) == Less + } +} + impl TotalOrd for LeafElt { ///Returns an ordering based on the keys of the LeafElts. fn cmp(&self, other: &LeafElt) -> Ordering { @@ -705,6 +764,12 @@ fn clone(&self) -> BranchElt { } } +impl Eq for BranchElt{ + fn eq(&self, other: &BranchElt) -> bool { + self.equals(other) + } +} + impl TotalEq for BranchElt{ ///TotalEq for BranchElts fn equals(&self, other: &BranchElt) -> bool { @@ -712,6 +777,12 @@ fn equals(&self, other: &BranchElt) -> bool { } } +impl Ord for BranchElt { + fn lt(&self, other: &BranchElt) -> bool { + self.cmp(other) == Less + } +} + impl TotalOrd for BranchElt { ///Fulfills TotalOrd for BranchElts fn cmp(&self, other: &BranchElt) -> Ordering { diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 6c059d3f40c..9193d319310 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -607,7 +607,7 @@ fn ne(&self, other: &DList) -> bool { } } -impl Ord for DList { +impl Ord for DList { fn lt(&self, other: &DList) -> bool { iter::order::lt(self.iter(), other.iter()) } diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 2a2493688e6..0d627317242 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -88,7 +88,7 @@ * */ -#[deriving(Clone, Eq, Encodable, Decodable, TotalOrd, TotalEq)] +#[deriving(Clone, Eq, Encodable, Decodable, Ord, TotalOrd, TotalEq)] struct WorkKey { kind: ~str, name: ~str diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 0b7450e5265..1bf2046c033 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -46,7 +46,7 @@ use syntax::crateid::CrateId; use syntax::parse::token; -#[deriving(Clone, Eq, TotalOrd, TotalEq)] +#[deriving(Clone, Eq, Ord, TotalOrd, TotalEq)] pub enum OutputType { OutputTypeBitcode, OutputTypeAssembly, diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 10d910636fc..10ec54d0dce 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -166,7 +166,7 @@ pub enum EntryFnType { EntryNone, } -#[deriving(Eq, Clone, TotalOrd, TotalEq)] +#[deriving(Eq, Ord, Clone, TotalOrd, TotalEq)] pub enum CrateType { CrateTypeExecutable, CrateTypeDylib, diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index effdbd8e451..877c8a6d592 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -525,7 +525,7 @@ pub fn lit_to_const(lit: &Lit) -> const_val { } } -fn compare_vals(a: T, b: T) -> Option { +fn compare_vals(a: T, b: T) -> Option { Some(if a == b { 0 } else if a < b { -1 } else { 1 }) } pub fn compare_const_vals(a: &const_val, b: &const_val) -> Option { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 9442a2144bd..c364e099009 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -633,13 +633,13 @@ pub fn is_bound(&self) -> bool { } } -#[deriving(Clone, Eq, TotalOrd, TotalEq, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Hash, Encodable, Decodable, Show)] pub struct FreeRegion { scope_id: NodeId, bound_region: BoundRegion } -#[deriving(Clone, Eq, TotalEq, TotalOrd, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Hash, Encodable, Decodable, Show)] pub enum BoundRegion { /// An anonymous region parameter for a given fn (&T) BrAnon(uint), diff --git a/src/libstd/cmp.rs b/src/libstd/cmp.rs index 291f1dd04d3..6975c9da3f0 100644 --- a/src/libstd/cmp.rs +++ b/src/libstd/cmp.rs @@ -42,8 +42,12 @@ fn ne(&self, other: &Self) -> bool { !self.eq(other) } } /// Trait for equality comparisons where `a == b` and `a != b` are strict inverses. -pub trait TotalEq { - fn equals(&self, other: &Self) -> bool; +pub trait TotalEq: Eq { + /// This method must return the same value as `eq`. It exists to prevent + /// deriving `TotalEq` from fields not implementing the `TotalEq` trait. + fn equals(&self, other: &Self) -> bool { + self.eq(other) + } } macro_rules! totaleq_impl( @@ -76,7 +80,7 @@ fn equals(&self, other: &$t) -> bool { *self == *other } pub enum Ordering { Less = -1, Equal = 0, Greater = 1 } /// Trait for types that form a total order -pub trait TotalOrd: TotalEq { +pub trait TotalOrd: TotalEq + Ord { fn cmp(&self, other: &Self) -> Ordering; } @@ -161,7 +165,7 @@ pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering { * (cf. IEEE 754-2008 section 5.11). */ #[lang="ord"] -pub trait Ord { +pub trait Ord: Eq { fn lt(&self, other: &Self) -> bool; #[inline] fn le(&self, other: &Self) -> bool { !other.lt(self) } @@ -169,8 +173,6 @@ fn le(&self, other: &Self) -> bool { !other.lt(self) } fn gt(&self, other: &Self) -> bool { other.lt(self) } #[inline] fn ge(&self, other: &Self) -> bool { !self.lt(other) } - - // FIXME (#12068): Add min/max/clamp default methods } /// The equivalence relation. Two values may be equivalent even if they are diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index a01a4bf3d62..6bf3cdf52ab 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -2033,7 +2033,7 @@ pub fn range_inclusive + Ord + Clone + One + ToPrimitive>(start: A, RangeInclusive{range: range(start, stop), done: false} } -impl + Eq + Ord + Clone + ToPrimitive> Iterator for RangeInclusive { +impl + Ord + Clone + ToPrimitive> Iterator for RangeInclusive { #[inline] fn next(&mut self) -> Option { match self.range.next() { @@ -2244,7 +2244,7 @@ pub fn ne>(mut a: T, mut b: T) -> bool { } /// Return `a` < `b` lexicographically (Using partial order, `Ord`) - pub fn lt>(mut a: T, mut b: T) -> bool { + pub fn lt>(mut a: T, mut b: T) -> bool { loop { match (a.next(), b.next()) { (None, None) => return false, @@ -2256,7 +2256,7 @@ pub fn lt>(mut a: T, mut b: T) -> bool { } /// Return `a` <= `b` lexicographically (Using partial order, `Ord`) - pub fn le>(mut a: T, mut b: T) -> bool { + pub fn le>(mut a: T, mut b: T) -> bool { loop { match (a.next(), b.next()) { (None, None) => return true, @@ -2268,7 +2268,7 @@ pub fn le>(mut a: T, mut b: T) -> bool { } /// Return `a` > `b` lexicographically (Using partial order, `Ord`) - pub fn gt>(mut a: T, mut b: T) -> bool { + pub fn gt>(mut a: T, mut b: T) -> bool { loop { match (a.next(), b.next()) { (None, None) => return false, @@ -2280,7 +2280,7 @@ pub fn gt>(mut a: T, mut b: T) -> bool { } /// Return `a` >= `b` lexicographically (Using partial order, `Ord`) - pub fn ge>(mut a: T, mut b: T) -> bool { + pub fn ge>(mut a: T, mut b: T) -> bool { loop { match (a.next(), b.next()) { (None, None) => return true, @@ -2978,6 +2978,12 @@ fn add(&self, _: &Foo) -> Foo { } } + impl Eq for Foo { + fn eq(&self, _: &Foo) -> bool { + true + } + } + impl Ord for Foo { fn lt(&self, _: &Foo) -> bool { false diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 633d6e92c70..7997c5747b4 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -40,7 +40,7 @@ use any::Any; use clone::Clone; use clone::DeepClone; -use cmp::{Eq, TotalEq, TotalOrd}; +use cmp::{Eq, TotalOrd}; use default::Default; use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize}; use kinds::Send; diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 59136c99ec9..69bf5f5d0fc 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -682,7 +682,7 @@ impl TotalOrd for ~[T] { fn cmp(&self, other: &~[T]) -> Ordering { self.as_slice().cmp(&other.as_slice()) } } - impl<'a, T: Eq + Ord> Ord for &'a [T] { + impl<'a, T: Ord> Ord for &'a [T] { fn lt(&self, other: & &'a [T]) -> bool { order::lt(self.iter(), other.iter()) } @@ -700,7 +700,7 @@ fn gt(&self, other: & &'a [T]) -> bool { } } - impl Ord for ~[T] { + impl Ord for ~[T] { #[inline] fn lt(&self, other: &~[T]) -> bool { self.as_slice() < other.as_slice() } #[inline] diff --git a/src/libstd/vec_ng.rs b/src/libstd/vec_ng.rs index 0a5a7c2da47..ae918bfa98b 100644 --- a/src/libstd/vec_ng.rs +++ b/src/libstd/vec_ng.rs @@ -13,7 +13,7 @@ use cast::{forget, transmute}; use clone::Clone; -use cmp::{Eq, Ordering, TotalEq, TotalOrd}; +use cmp::{Ord, Eq, Ordering, TotalEq, TotalOrd}; use container::Container; use default::Default; use fmt; @@ -136,21 +136,28 @@ fn extend>(&mut self, iterator: &mut I) { } } -impl Eq for Vec { +impl Eq for Vec { #[inline] fn eq(&self, other: &Vec) -> bool { self.as_slice() == other.as_slice() } } -impl TotalEq for Vec { +impl Ord for Vec { + #[inline] + fn lt(&self, other: &Vec) -> bool { + self.as_slice() < other.as_slice() + } +} + +impl TotalEq for Vec { #[inline] fn equals(&self, other: &Vec) -> bool { self.as_slice().equals(&other.as_slice()) } } -impl TotalOrd for Vec { +impl TotalOrd for Vec { #[inline] fn cmp(&self, other: &Vec) -> Ordering { self.as_slice().cmp(&other.as_slice()) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a8480b6cfeb..0a959993517 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -39,7 +39,7 @@ pub fn P(value: T) -> P { // table) and a SyntaxContext to track renaming and // macro expansion per Flatt et al., "Macros // That Work Together" -#[deriving(Clone, Hash, TotalEq, TotalOrd, Show)] +#[deriving(Clone, Hash, Ord, TotalEq, TotalOrd, Show)] pub struct Ident { name: Name, ctxt: SyntaxContext @@ -151,7 +151,7 @@ pub struct PathSegment { pub type NodeId = u32; -#[deriving(Clone, TotalEq, TotalOrd, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, TotalEq, TotalOrd, Ord, Eq, Encodable, Decodable, Hash, Show)] pub struct DefId { krate: CrateNum, node: NodeId, diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index a8f3489cb87..2ddea19b4c9 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -26,7 +26,7 @@ // Code implementation -#[deriving(Eq, TotalOrd, TotalEq)] +#[deriving(Eq, Ord, TotalOrd, TotalEq)] struct Code(u64); impl Code { diff --git a/src/test/compile-fail/deriving-span-Ord-enum-struct-variant.rs b/src/test/compile-fail/deriving-span-Ord-enum-struct-variant.rs index e3e442e70cf..319ba14c31c 100644 --- a/src/test/compile-fail/deriving-span-Ord-enum-struct-variant.rs +++ b/src/test/compile-fail/deriving-span-Ord-enum-struct-variant.rs @@ -13,10 +13,10 @@ #[feature(struct_variant)]; extern crate extra; - +#[deriving(Eq)] struct Error; -#[deriving(Ord)] +#[deriving(Eq, Ord)] enum Enum { A { x: Error //~ ERROR diff --git a/src/test/compile-fail/deriving-span-Ord-enum.rs b/src/test/compile-fail/deriving-span-Ord-enum.rs index 41e6c2c9e8d..0067546d1aa 100644 --- a/src/test/compile-fail/deriving-span-Ord-enum.rs +++ b/src/test/compile-fail/deriving-span-Ord-enum.rs @@ -13,10 +13,10 @@ #[feature(struct_variant)]; extern crate extra; - +#[deriving(Eq)] struct Error; -#[deriving(Ord)] +#[deriving(Eq, Ord)] enum Enum { A( Error //~ ERROR diff --git a/src/test/compile-fail/deriving-span-Ord-struct.rs b/src/test/compile-fail/deriving-span-Ord-struct.rs index 2caf68a26fc..a64f51f142d 100644 --- a/src/test/compile-fail/deriving-span-Ord-struct.rs +++ b/src/test/compile-fail/deriving-span-Ord-struct.rs @@ -13,10 +13,10 @@ #[feature(struct_variant)]; extern crate extra; - +#[deriving(Eq)] struct Error; -#[deriving(Ord)] +#[deriving(Eq, Ord)] struct Struct { x: Error //~ ERROR //~^ ERROR diff --git a/src/test/compile-fail/deriving-span-Ord-tuple-struct.rs b/src/test/compile-fail/deriving-span-Ord-tuple-struct.rs index c783befa391..d289a426932 100644 --- a/src/test/compile-fail/deriving-span-Ord-tuple-struct.rs +++ b/src/test/compile-fail/deriving-span-Ord-tuple-struct.rs @@ -13,10 +13,10 @@ #[feature(struct_variant)]; extern crate extra; - +#[deriving(Eq)] struct Error; -#[deriving(Ord)] +#[deriving(Eq, Ord)] struct Struct( Error //~ ERROR //~^ ERROR diff --git a/src/test/compile-fail/deriving-span-TotalEq-enum-struct-variant.rs b/src/test/compile-fail/deriving-span-TotalEq-enum-struct-variant.rs index f054e9e7e77..7fc030bdb36 100644 --- a/src/test/compile-fail/deriving-span-TotalEq-enum-struct-variant.rs +++ b/src/test/compile-fail/deriving-span-TotalEq-enum-struct-variant.rs @@ -13,10 +13,10 @@ #[feature(struct_variant)]; extern crate extra; - +#[deriving(Eq)] struct Error; -#[deriving(TotalEq)] +#[deriving(Eq, TotalEq)] enum Enum { A { x: Error //~ ERROR diff --git a/src/test/compile-fail/deriving-span-TotalEq-enum.rs b/src/test/compile-fail/deriving-span-TotalEq-enum.rs index 38b8d55bcd8..166311e030b 100644 --- a/src/test/compile-fail/deriving-span-TotalEq-enum.rs +++ b/src/test/compile-fail/deriving-span-TotalEq-enum.rs @@ -13,10 +13,10 @@ #[feature(struct_variant)]; extern crate extra; - +#[deriving(Eq)] struct Error; -#[deriving(TotalEq)] +#[deriving(Eq, TotalEq)] enum Enum { A( Error //~ ERROR diff --git a/src/test/compile-fail/deriving-span-TotalEq-struct.rs b/src/test/compile-fail/deriving-span-TotalEq-struct.rs index 66e5ef57a00..f96c41a3865 100644 --- a/src/test/compile-fail/deriving-span-TotalEq-struct.rs +++ b/src/test/compile-fail/deriving-span-TotalEq-struct.rs @@ -13,10 +13,10 @@ #[feature(struct_variant)]; extern crate extra; - +#[deriving(Eq)] struct Error; -#[deriving(TotalEq)] +#[deriving(Eq, TotalEq)] struct Struct { x: Error //~ ERROR } diff --git a/src/test/compile-fail/deriving-span-TotalEq-tuple-struct.rs b/src/test/compile-fail/deriving-span-TotalEq-tuple-struct.rs index dd0be2dc04a..4b825adb8cf 100644 --- a/src/test/compile-fail/deriving-span-TotalEq-tuple-struct.rs +++ b/src/test/compile-fail/deriving-span-TotalEq-tuple-struct.rs @@ -13,10 +13,10 @@ #[feature(struct_variant)]; extern crate extra; - +#[deriving(Eq)] struct Error; -#[deriving(TotalEq)] +#[deriving(Eq, TotalEq)] struct Struct( Error //~ ERROR ); diff --git a/src/test/compile-fail/deriving-span-TotalOrd-enum-struct-variant.rs b/src/test/compile-fail/deriving-span-TotalOrd-enum-struct-variant.rs index 76bcd332562..7be90a2aa76 100644 --- a/src/test/compile-fail/deriving-span-TotalOrd-enum-struct-variant.rs +++ b/src/test/compile-fail/deriving-span-TotalOrd-enum-struct-variant.rs @@ -13,10 +13,10 @@ #[feature(struct_variant)]; extern crate extra; -#[deriving(TotalEq)] +#[deriving(Eq, Ord, TotalEq)] struct Error; -#[deriving(TotalOrd,TotalEq)] +#[deriving(Eq, Ord, TotalOrd,TotalEq)] enum Enum { A { x: Error //~ ERROR diff --git a/src/test/compile-fail/deriving-span-TotalOrd-enum.rs b/src/test/compile-fail/deriving-span-TotalOrd-enum.rs index 303e35108fe..ba97b28d18c 100644 --- a/src/test/compile-fail/deriving-span-TotalOrd-enum.rs +++ b/src/test/compile-fail/deriving-span-TotalOrd-enum.rs @@ -13,10 +13,10 @@ #[feature(struct_variant)]; extern crate extra; -#[deriving(TotalEq)] +#[deriving(Eq, Ord, TotalEq)] struct Error; -#[deriving(TotalOrd,TotalEq)] +#[deriving(Eq, Ord, TotalOrd,TotalEq)] enum Enum { A( Error //~ ERROR diff --git a/src/test/compile-fail/deriving-span-TotalOrd-struct.rs b/src/test/compile-fail/deriving-span-TotalOrd-struct.rs index bbcc3ae7e04..014a5b97e36 100644 --- a/src/test/compile-fail/deriving-span-TotalOrd-struct.rs +++ b/src/test/compile-fail/deriving-span-TotalOrd-struct.rs @@ -13,10 +13,10 @@ #[feature(struct_variant)]; extern crate extra; -#[deriving(TotalEq)] +#[deriving(Eq, Ord, TotalEq)] struct Error; -#[deriving(TotalOrd,TotalEq)] +#[deriving(Eq, Ord, TotalOrd,TotalEq)] struct Struct { x: Error //~ ERROR } diff --git a/src/test/compile-fail/deriving-span-TotalOrd-tuple-struct.rs b/src/test/compile-fail/deriving-span-TotalOrd-tuple-struct.rs index 4e8697749e7..7e4d5b2201b 100644 --- a/src/test/compile-fail/deriving-span-TotalOrd-tuple-struct.rs +++ b/src/test/compile-fail/deriving-span-TotalOrd-tuple-struct.rs @@ -13,10 +13,10 @@ #[feature(struct_variant)]; extern crate extra; -#[deriving(TotalEq)] +#[deriving(Eq, Ord, TotalEq)] struct Error; -#[deriving(TotalOrd,TotalEq)] +#[deriving(Eq, Ord, TotalOrd,TotalEq)] struct Struct( Error //~ ERROR ); diff --git a/src/test/compile-fail/issue-3344.rs b/src/test/compile-fail/issue-3344.rs index 88414dddd66..e79a5871e70 100644 --- a/src/test/compile-fail/issue-3344.rs +++ b/src/test/compile-fail/issue-3344.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[deriving(Eq)] struct thing(uint); impl Ord for thing { //~ ERROR not all trait methods implemented, missing: `lt` fn le(&self, other: &thing) -> bool { true } diff --git a/src/test/run-pass/cmp-default.rs b/src/test/run-pass/cmp-default.rs index 3650564d929..2ab6a70839f 100644 --- a/src/test/run-pass/cmp-default.rs +++ b/src/test/run-pass/cmp-default.rs @@ -22,6 +22,14 @@ fn eq(&self, other: &Fool) -> bool { struct Int(int); +impl Eq for Int { + fn eq(&self, other: &Int) -> bool { + let Int(this) = *self; + let Int(other) = *other; + this == other + } +} + impl Ord for Int { fn lt(&self, other: &Int) -> bool { let Int(this) = *self; @@ -32,6 +40,14 @@ fn lt(&self, other: &Int) -> bool { struct RevInt(int); +impl Eq for RevInt { + fn eq(&self, other: &RevInt) -> bool { + let RevInt(this) = *self; + let RevInt(other) = *other; + this == other + } +} + impl Ord for RevInt { fn lt(&self, other: &RevInt) -> bool { let RevInt(this) = *self; diff --git a/src/test/run-pass/vector-sort-failure-safe.rs b/src/test/run-pass/vector-sort-failure-safe.rs index 74f27e48090..2c4a8aece19 100644 --- a/src/test/run-pass/vector-sort-failure-safe.rs +++ b/src/test/run-pass/vector-sort-failure-safe.rs @@ -15,7 +15,7 @@ static mut drop_counts: [uint, .. MAX_LEN] = [0, .. MAX_LEN]; static mut clone_count: uint = 0; -#[deriving(Rand, Ord, TotalEq, TotalOrd)] +#[deriving(Rand, Eq, Ord, TotalEq, TotalOrd)] struct DropCounter { x: uint, clone_num: uint } impl Clone for DropCounter {