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 171203b00b806..6411b6bc97435 100644 --- a/src/libcollections/btree.rs +++ b/src/libcollections/btree.rs @@ -92,6 +92,11 @@ impl Clone for 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 @@ impl TotalEq for BTree { } } +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 @@ impl Clone for 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 @@ impl TotalEq for Node { } } +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 @@ impl Clone for 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 @@ impl TotalEq for Leaf { } } +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 @@ impl Clone for 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 @@ impl TotalEq for Branch { } } +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 @@ impl Clone for 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 @@ impl TotalEq for LeafElt { } } +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 @@ impl Clone for 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 @@ impl TotalEq for BranchElt{ } } +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 6c059d3f40c42..9193d31931067 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -607,7 +607,7 @@ impl Eq for DList { } } -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 2a2493688e62a..0d62731724283 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -88,7 +88,7 @@ use std::io::{File, MemWriter}; * */ -#[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 0b7450e526521..1bf2046c03312 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -46,7 +46,7 @@ use syntax::attr::AttrMetaMethods; 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 10d910636fca7..10ec54d0dce0f 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 effdbd8e45176..877c8a6d592cd 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 9442a2144bdab..c364e099009fc 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -633,13 +633,13 @@ impl Region { } } -#[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 291f1dd04d30d..6975c9da3f08b 100644 --- a/src/libstd/cmp.rs +++ b/src/libstd/cmp.rs @@ -42,8 +42,12 @@ pub trait Eq { } /// 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 @@ totaleq_impl!(char) 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 @@ pub trait Ord { 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 a01a4bf3d6273..6bf3cdf52abac 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 mod order { } /// 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 mod order { } /// 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 mod order { } /// 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 mod order { } /// 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 @@ mod tests { } } + 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 633d6e92c704c..7997c5747b40e 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 59136c99ec986..69bf5f5d0fcda 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -682,7 +682,7 @@ pub mod traits { 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 @@ pub mod traits { } } - 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 0a5a7c2da47c1..ae918bfa98b32 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 @@ impl Extendable for Vec { } } -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 a8480b6cfeb34..0a95999351757 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 type CrateNum = u32; 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 a8f3489cb8793..2ddea19b4c9df 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -26,7 +26,7 @@ static OCCURRENCES: [&'static str, ..5] = [ // 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 e3e442e70cf99..319ba14c31c96 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 41e6c2c9e8dad..0067546d1aa0a 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 2caf68a26fcc2..a64f51f142dec 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 c783befa3919c..d289a42693292 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 f054e9e7e77f6..7fc030bdb36f6 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 38b8d55bcd83a..166311e030b1e 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 66e5ef57a00b5..f96c41a3865c1 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 dd0be2dc04a65..4b825adb8cfab 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 76bcd33256240..7be90a2aa769d 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 303e35108feea..ba97b28d18c70 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 bbcc3ae7e047a..014a5b97e3650 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 4e8697749e76e..7e4d5b2201b3b 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 88414dddd660c..e79a5871e70c6 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 3650564d929ca..2ab6a70839f0e 100644 --- a/src/test/run-pass/cmp-default.rs +++ b/src/test/run-pass/cmp-default.rs @@ -22,6 +22,14 @@ impl Eq for Fool { 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 @@ impl Ord for Int { 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 74f27e480909c..2c4a8aece194d 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 MAX_LEN: uint = 20; 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 {