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.
This commit is contained in:
parent
33768c46ec
commit
4d7d101a76
29 changed files with 156 additions and 53 deletions
|
@ -92,6 +92,11 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for BTree<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: TotalOrd, V: TotalEq> Eq for BTree<K, V> {
|
||||||
|
fn eq(&self, other: &BTree<K, V>) -> bool {
|
||||||
|
self.equals(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: TotalOrd, V: TotalEq> TotalEq for BTree<K, V> {
|
impl<K: TotalOrd, V: TotalEq> TotalEq for BTree<K, V> {
|
||||||
///Testing equality on BTrees by comparing the root.
|
///Testing equality on BTrees by comparing the root.
|
||||||
|
@ -100,6 +105,12 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for BTree<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: TotalOrd, V: TotalEq> Ord for BTree<K, V> {
|
||||||
|
fn lt(&self, other: &BTree<K, V>) -> bool {
|
||||||
|
self.cmp(other) == Less
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: TotalOrd, V: TotalEq> TotalOrd for BTree<K, V> {
|
impl<K: TotalOrd, V: TotalEq> TotalOrd for BTree<K, V> {
|
||||||
///Returns an ordering based on the root nodes of each BTree.
|
///Returns an ordering based on the root nodes of each BTree.
|
||||||
fn cmp(&self, other: &BTree<K, V>) -> Ordering {
|
fn cmp(&self, other: &BTree<K, V>) -> Ordering {
|
||||||
|
@ -191,6 +202,12 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for Node<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: TotalOrd, V: TotalEq> Eq for Node<K, V> {
|
||||||
|
fn eq(&self, other: &Node<K, V>) -> bool {
|
||||||
|
self.equals(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: TotalOrd, V: TotalEq> TotalEq for Node<K, V> {
|
impl<K: TotalOrd, V: TotalEq> TotalEq for Node<K, V> {
|
||||||
///Returns whether two nodes are equal based on the keys of each element.
|
///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.
|
///Two nodes are equal if all of their keys are the same.
|
||||||
|
@ -215,6 +232,12 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for Node<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: TotalOrd, V: TotalEq> Ord for Node<K, V> {
|
||||||
|
fn lt(&self, other: &Node<K, V>) -> bool {
|
||||||
|
self.cmp(other) == Less
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: TotalOrd, V: TotalEq> TotalOrd for Node<K, V> {
|
impl<K: TotalOrd, V: TotalEq> TotalOrd for Node<K, V> {
|
||||||
///Implementation of TotalOrd for Nodes.
|
///Implementation of TotalOrd for Nodes.
|
||||||
fn cmp(&self, other: &Node<K, V>) -> Ordering {
|
fn cmp(&self, other: &Node<K, V>) -> Ordering {
|
||||||
|
@ -380,6 +403,12 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for Leaf<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: TotalOrd, V: TotalEq> Eq for Leaf<K, V> {
|
||||||
|
fn eq(&self, other: &Leaf<K, V>) -> bool {
|
||||||
|
self.equals(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: TotalOrd, V: TotalEq> TotalEq for Leaf<K, V> {
|
impl<K: TotalOrd, V: TotalEq> TotalEq for Leaf<K, V> {
|
||||||
///Implementation of equals function for leaves that compares LeafElts.
|
///Implementation of equals function for leaves that compares LeafElts.
|
||||||
fn equals(&self, other: &Leaf<K, V>) -> bool {
|
fn equals(&self, other: &Leaf<K, V>) -> bool {
|
||||||
|
@ -387,6 +416,12 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for Leaf<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: TotalOrd, V: TotalEq> Ord for Leaf<K, V> {
|
||||||
|
fn lt(&self, other: &Leaf<K, V>) -> bool {
|
||||||
|
self.cmp(other) == Less
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: TotalOrd, V: TotalEq> TotalOrd for Leaf<K, V> {
|
impl<K: TotalOrd, V: TotalEq> TotalOrd for Leaf<K, V> {
|
||||||
///Returns an ordering based on the first element of each Leaf.
|
///Returns an ordering based on the first element of each Leaf.
|
||||||
fn cmp(&self, other: &Leaf<K, V>) -> Ordering {
|
fn cmp(&self, other: &Leaf<K, V>) -> Ordering {
|
||||||
|
@ -602,6 +637,12 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for Branch<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: TotalOrd, V: TotalEq> Eq for Branch<K, V> {
|
||||||
|
fn eq(&self, other: &Branch<K, V>) -> bool {
|
||||||
|
self.equals(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: TotalOrd, V: TotalEq> TotalEq for Branch<K, V> {
|
impl<K: TotalOrd, V: TotalEq> TotalEq for Branch<K, V> {
|
||||||
///Equals function for Branches--compares all the elements in each branch
|
///Equals function for Branches--compares all the elements in each branch
|
||||||
fn equals(&self, other: &Branch<K, V>) -> bool {
|
fn equals(&self, other: &Branch<K, V>) -> bool {
|
||||||
|
@ -609,6 +650,12 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for Branch<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: TotalOrd, V: TotalEq> Ord for Branch<K, V> {
|
||||||
|
fn lt(&self, other: &Branch<K, V>) -> bool {
|
||||||
|
self.cmp(other) == Less
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: TotalOrd, V: TotalEq> TotalOrd for Branch<K, V> {
|
impl<K: TotalOrd, V: TotalEq> TotalOrd for Branch<K, V> {
|
||||||
///Compares the first elements of two branches to determine an ordering
|
///Compares the first elements of two branches to determine an ordering
|
||||||
fn cmp(&self, other: &Branch<K, V>) -> Ordering {
|
fn cmp(&self, other: &Branch<K, V>) -> Ordering {
|
||||||
|
@ -663,6 +710,12 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for LeafElt<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: TotalOrd, V: TotalEq> Eq for LeafElt<K, V> {
|
||||||
|
fn eq(&self, other: &LeafElt<K, V>) -> bool {
|
||||||
|
self.equals(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: TotalOrd, V: TotalEq> TotalEq for LeafElt<K, V> {
|
impl<K: TotalOrd, V: TotalEq> TotalEq for LeafElt<K, V> {
|
||||||
///TotalEq for LeafElts
|
///TotalEq for LeafElts
|
||||||
fn equals(&self, other: &LeafElt<K, V>) -> bool {
|
fn equals(&self, other: &LeafElt<K, V>) -> bool {
|
||||||
|
@ -670,6 +723,12 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for LeafElt<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: TotalOrd, V: TotalEq> Ord for LeafElt<K, V> {
|
||||||
|
fn lt(&self, other: &LeafElt<K, V>) -> bool {
|
||||||
|
self.cmp(other) == Less
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: TotalOrd, V: TotalEq> TotalOrd for LeafElt<K, V> {
|
impl<K: TotalOrd, V: TotalEq> TotalOrd for LeafElt<K, V> {
|
||||||
///Returns an ordering based on the keys of the LeafElts.
|
///Returns an ordering based on the keys of the LeafElts.
|
||||||
fn cmp(&self, other: &LeafElt<K, V>) -> Ordering {
|
fn cmp(&self, other: &LeafElt<K, V>) -> Ordering {
|
||||||
|
@ -705,6 +764,12 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for BranchElt<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: TotalOrd, V: TotalEq> Eq for BranchElt<K, V>{
|
||||||
|
fn eq(&self, other: &BranchElt<K, V>) -> bool {
|
||||||
|
self.equals(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: TotalOrd, V: TotalEq> TotalEq for BranchElt<K, V>{
|
impl<K: TotalOrd, V: TotalEq> TotalEq for BranchElt<K, V>{
|
||||||
///TotalEq for BranchElts
|
///TotalEq for BranchElts
|
||||||
fn equals(&self, other: &BranchElt<K, V>) -> bool {
|
fn equals(&self, other: &BranchElt<K, V>) -> bool {
|
||||||
|
@ -712,6 +777,12 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for BranchElt<K, V>{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: TotalOrd, V: TotalEq> Ord for BranchElt<K, V> {
|
||||||
|
fn lt(&self, other: &BranchElt<K, V>) -> bool {
|
||||||
|
self.cmp(other) == Less
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K: TotalOrd, V: TotalEq> TotalOrd for BranchElt<K, V> {
|
impl<K: TotalOrd, V: TotalEq> TotalOrd for BranchElt<K, V> {
|
||||||
///Fulfills TotalOrd for BranchElts
|
///Fulfills TotalOrd for BranchElts
|
||||||
fn cmp(&self, other: &BranchElt<K, V>) -> Ordering {
|
fn cmp(&self, other: &BranchElt<K, V>) -> Ordering {
|
||||||
|
|
|
@ -607,7 +607,7 @@ impl<A: Eq> Eq for DList<A> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Eq + Ord> Ord for DList<A> {
|
impl<A: Ord> Ord for DList<A> {
|
||||||
fn lt(&self, other: &DList<A>) -> bool {
|
fn lt(&self, other: &DList<A>) -> bool {
|
||||||
iter::order::lt(self.iter(), other.iter())
|
iter::order::lt(self.iter(), other.iter())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
struct WorkKey {
|
||||||
kind: ~str,
|
kind: ~str,
|
||||||
name: ~str
|
name: ~str
|
||||||
|
|
|
@ -46,7 +46,7 @@ use syntax::attr::AttrMetaMethods;
|
||||||
use syntax::crateid::CrateId;
|
use syntax::crateid::CrateId;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
|
|
||||||
#[deriving(Clone, Eq, TotalOrd, TotalEq)]
|
#[deriving(Clone, Eq, Ord, TotalOrd, TotalEq)]
|
||||||
pub enum OutputType {
|
pub enum OutputType {
|
||||||
OutputTypeBitcode,
|
OutputTypeBitcode,
|
||||||
OutputTypeAssembly,
|
OutputTypeAssembly,
|
||||||
|
|
|
@ -166,7 +166,7 @@ pub enum EntryFnType {
|
||||||
EntryNone,
|
EntryNone,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq, Clone, TotalOrd, TotalEq)]
|
#[deriving(Eq, Ord, Clone, TotalOrd, TotalEq)]
|
||||||
pub enum CrateType {
|
pub enum CrateType {
|
||||||
CrateTypeExecutable,
|
CrateTypeExecutable,
|
||||||
CrateTypeDylib,
|
CrateTypeDylib,
|
||||||
|
|
|
@ -525,7 +525,7 @@ pub fn lit_to_const(lit: &Lit) -> const_val {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_vals<T : Eq + Ord>(a: T, b: T) -> Option<int> {
|
fn compare_vals<T: Ord>(a: T, b: T) -> Option<int> {
|
||||||
Some(if a == b { 0 } else if a < b { -1 } else { 1 })
|
Some(if a == b { 0 } else if a < b { -1 } else { 1 })
|
||||||
}
|
}
|
||||||
pub fn compare_const_vals(a: &const_val, b: &const_val) -> Option<int> {
|
pub fn compare_const_vals(a: &const_val, b: &const_val) -> Option<int> {
|
||||||
|
|
|
@ -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 {
|
pub struct FreeRegion {
|
||||||
scope_id: NodeId,
|
scope_id: NodeId,
|
||||||
bound_region: BoundRegion
|
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 {
|
pub enum BoundRegion {
|
||||||
/// An anonymous region parameter for a given fn (&T)
|
/// An anonymous region parameter for a given fn (&T)
|
||||||
BrAnon(uint),
|
BrAnon(uint),
|
||||||
|
|
|
@ -42,8 +42,12 @@ pub trait Eq {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for equality comparisons where `a == b` and `a != b` are strict inverses.
|
/// Trait for equality comparisons where `a == b` and `a != b` are strict inverses.
|
||||||
pub trait TotalEq {
|
pub trait TotalEq: Eq {
|
||||||
fn equals(&self, other: &Self) -> bool;
|
/// 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(
|
macro_rules! totaleq_impl(
|
||||||
|
@ -76,7 +80,7 @@ totaleq_impl!(char)
|
||||||
pub enum Ordering { Less = -1, Equal = 0, Greater = 1 }
|
pub enum Ordering { Less = -1, Equal = 0, Greater = 1 }
|
||||||
|
|
||||||
/// Trait for types that form a total order
|
/// Trait for types that form a total order
|
||||||
pub trait TotalOrd: TotalEq {
|
pub trait TotalOrd: TotalEq + Ord {
|
||||||
fn cmp(&self, other: &Self) -> Ordering;
|
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).
|
* (cf. IEEE 754-2008 section 5.11).
|
||||||
*/
|
*/
|
||||||
#[lang="ord"]
|
#[lang="ord"]
|
||||||
pub trait Ord {
|
pub trait Ord: Eq {
|
||||||
fn lt(&self, other: &Self) -> bool;
|
fn lt(&self, other: &Self) -> bool;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn le(&self, other: &Self) -> bool { !other.lt(self) }
|
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) }
|
fn gt(&self, other: &Self) -> bool { other.lt(self) }
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ge(&self, other: &Self) -> bool { !self.lt(other) }
|
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
|
/// The equivalence relation. Two values may be equivalent even if they are
|
||||||
|
|
|
@ -2033,7 +2033,7 @@ pub fn range_inclusive<A: Add<A, A> + Ord + Clone + One + ToPrimitive>(start: A,
|
||||||
RangeInclusive{range: range(start, stop), done: false}
|
RangeInclusive{range: range(start, stop), done: false}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Add<A, A> + Eq + Ord + Clone + ToPrimitive> Iterator<A> for RangeInclusive<A> {
|
impl<A: Add<A, A> + Ord + Clone + ToPrimitive> Iterator<A> for RangeInclusive<A> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<A> {
|
fn next(&mut self) -> Option<A> {
|
||||||
match self.range.next() {
|
match self.range.next() {
|
||||||
|
@ -2244,7 +2244,7 @@ pub mod order {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return `a` < `b` lexicographically (Using partial order, `Ord`)
|
/// Return `a` < `b` lexicographically (Using partial order, `Ord`)
|
||||||
pub fn lt<A: Eq + Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
|
pub fn lt<A: Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
|
||||||
loop {
|
loop {
|
||||||
match (a.next(), b.next()) {
|
match (a.next(), b.next()) {
|
||||||
(None, None) => return false,
|
(None, None) => return false,
|
||||||
|
@ -2256,7 +2256,7 @@ pub mod order {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return `a` <= `b` lexicographically (Using partial order, `Ord`)
|
/// Return `a` <= `b` lexicographically (Using partial order, `Ord`)
|
||||||
pub fn le<A: Eq + Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
|
pub fn le<A: Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
|
||||||
loop {
|
loop {
|
||||||
match (a.next(), b.next()) {
|
match (a.next(), b.next()) {
|
||||||
(None, None) => return true,
|
(None, None) => return true,
|
||||||
|
@ -2268,7 +2268,7 @@ pub mod order {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return `a` > `b` lexicographically (Using partial order, `Ord`)
|
/// Return `a` > `b` lexicographically (Using partial order, `Ord`)
|
||||||
pub fn gt<A: Eq + Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
|
pub fn gt<A: Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
|
||||||
loop {
|
loop {
|
||||||
match (a.next(), b.next()) {
|
match (a.next(), b.next()) {
|
||||||
(None, None) => return false,
|
(None, None) => return false,
|
||||||
|
@ -2280,7 +2280,7 @@ pub mod order {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return `a` >= `b` lexicographically (Using partial order, `Ord`)
|
/// Return `a` >= `b` lexicographically (Using partial order, `Ord`)
|
||||||
pub fn ge<A: Eq + Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
|
pub fn ge<A: Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
|
||||||
loop {
|
loop {
|
||||||
match (a.next(), b.next()) {
|
match (a.next(), b.next()) {
|
||||||
(None, None) => return true,
|
(None, None) => return true,
|
||||||
|
@ -2978,6 +2978,12 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Eq for Foo {
|
||||||
|
fn eq(&self, _: &Foo) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Ord for Foo {
|
impl Ord for Foo {
|
||||||
fn lt(&self, _: &Foo) -> bool {
|
fn lt(&self, _: &Foo) -> bool {
|
||||||
false
|
false
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
use any::Any;
|
use any::Any;
|
||||||
use clone::Clone;
|
use clone::Clone;
|
||||||
use clone::DeepClone;
|
use clone::DeepClone;
|
||||||
use cmp::{Eq, TotalEq, TotalOrd};
|
use cmp::{Eq, TotalOrd};
|
||||||
use default::Default;
|
use default::Default;
|
||||||
use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize};
|
use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize};
|
||||||
use kinds::Send;
|
use kinds::Send;
|
||||||
|
|
|
@ -682,7 +682,7 @@ pub mod traits {
|
||||||
fn cmp(&self, other: &~[T]) -> Ordering { self.as_slice().cmp(&other.as_slice()) }
|
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 {
|
fn lt(&self, other: & &'a [T]) -> bool {
|
||||||
order::lt(self.iter(), other.iter())
|
order::lt(self.iter(), other.iter())
|
||||||
}
|
}
|
||||||
|
@ -700,7 +700,7 @@ pub mod traits {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Eq + Ord> Ord for ~[T] {
|
impl<T: Ord> Ord for ~[T] {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn lt(&self, other: &~[T]) -> bool { self.as_slice() < other.as_slice() }
|
fn lt(&self, other: &~[T]) -> bool { self.as_slice() < other.as_slice() }
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
use cast::{forget, transmute};
|
use cast::{forget, transmute};
|
||||||
use clone::Clone;
|
use clone::Clone;
|
||||||
use cmp::{Eq, Ordering, TotalEq, TotalOrd};
|
use cmp::{Ord, Eq, Ordering, TotalEq, TotalOrd};
|
||||||
use container::Container;
|
use container::Container;
|
||||||
use default::Default;
|
use default::Default;
|
||||||
use fmt;
|
use fmt;
|
||||||
|
@ -136,21 +136,28 @@ impl<T> Extendable<T> for Vec<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Eq> Eq for Vec<T> {
|
impl<T: Eq> Eq for Vec<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &Vec<T>) -> bool {
|
fn eq(&self, other: &Vec<T>) -> bool {
|
||||||
self.as_slice() == other.as_slice()
|
self.as_slice() == other.as_slice()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:TotalEq> TotalEq for Vec<T> {
|
impl<T: Ord> Ord for Vec<T> {
|
||||||
|
#[inline]
|
||||||
|
fn lt(&self, other: &Vec<T>) -> bool {
|
||||||
|
self.as_slice() < other.as_slice()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: TotalEq> TotalEq for Vec<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn equals(&self, other: &Vec<T>) -> bool {
|
fn equals(&self, other: &Vec<T>) -> bool {
|
||||||
self.as_slice().equals(&other.as_slice())
|
self.as_slice().equals(&other.as_slice())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:TotalOrd> TotalOrd for Vec<T> {
|
impl<T: TotalOrd> TotalOrd for Vec<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cmp(&self, other: &Vec<T>) -> Ordering {
|
fn cmp(&self, other: &Vec<T>) -> Ordering {
|
||||||
self.as_slice().cmp(&other.as_slice())
|
self.as_slice().cmp(&other.as_slice())
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub fn P<T: 'static>(value: T) -> P<T> {
|
||||||
// table) and a SyntaxContext to track renaming and
|
// table) and a SyntaxContext to track renaming and
|
||||||
// macro expansion per Flatt et al., "Macros
|
// macro expansion per Flatt et al., "Macros
|
||||||
// That Work Together"
|
// That Work Together"
|
||||||
#[deriving(Clone, Hash, TotalEq, TotalOrd, Show)]
|
#[deriving(Clone, Hash, Ord, TotalEq, TotalOrd, Show)]
|
||||||
pub struct Ident {
|
pub struct Ident {
|
||||||
name: Name,
|
name: Name,
|
||||||
ctxt: SyntaxContext
|
ctxt: SyntaxContext
|
||||||
|
@ -151,7 +151,7 @@ pub type CrateNum = u32;
|
||||||
|
|
||||||
pub type NodeId = 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 {
|
pub struct DefId {
|
||||||
krate: CrateNum,
|
krate: CrateNum,
|
||||||
node: NodeId,
|
node: NodeId,
|
||||||
|
|
|
@ -26,7 +26,7 @@ static OCCURRENCES: [&'static str, ..5] = [
|
||||||
|
|
||||||
// Code implementation
|
// Code implementation
|
||||||
|
|
||||||
#[deriving(Eq, TotalOrd, TotalEq)]
|
#[deriving(Eq, Ord, TotalOrd, TotalEq)]
|
||||||
struct Code(u64);
|
struct Code(u64);
|
||||||
|
|
||||||
impl Code {
|
impl Code {
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
#[feature(struct_variant)];
|
#[feature(struct_variant)];
|
||||||
extern crate extra;
|
extern crate extra;
|
||||||
|
|
||||||
|
#[deriving(Eq)]
|
||||||
struct Error;
|
struct Error;
|
||||||
|
|
||||||
#[deriving(Ord)]
|
#[deriving(Eq, Ord)]
|
||||||
enum Enum {
|
enum Enum {
|
||||||
A {
|
A {
|
||||||
x: Error //~ ERROR
|
x: Error //~ ERROR
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
#[feature(struct_variant)];
|
#[feature(struct_variant)];
|
||||||
extern crate extra;
|
extern crate extra;
|
||||||
|
|
||||||
|
#[deriving(Eq)]
|
||||||
struct Error;
|
struct Error;
|
||||||
|
|
||||||
#[deriving(Ord)]
|
#[deriving(Eq, Ord)]
|
||||||
enum Enum {
|
enum Enum {
|
||||||
A(
|
A(
|
||||||
Error //~ ERROR
|
Error //~ ERROR
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
#[feature(struct_variant)];
|
#[feature(struct_variant)];
|
||||||
extern crate extra;
|
extern crate extra;
|
||||||
|
|
||||||
|
#[deriving(Eq)]
|
||||||
struct Error;
|
struct Error;
|
||||||
|
|
||||||
#[deriving(Ord)]
|
#[deriving(Eq, Ord)]
|
||||||
struct Struct {
|
struct Struct {
|
||||||
x: Error //~ ERROR
|
x: Error //~ ERROR
|
||||||
//~^ ERROR
|
//~^ ERROR
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
#[feature(struct_variant)];
|
#[feature(struct_variant)];
|
||||||
extern crate extra;
|
extern crate extra;
|
||||||
|
|
||||||
|
#[deriving(Eq)]
|
||||||
struct Error;
|
struct Error;
|
||||||
|
|
||||||
#[deriving(Ord)]
|
#[deriving(Eq, Ord)]
|
||||||
struct Struct(
|
struct Struct(
|
||||||
Error //~ ERROR
|
Error //~ ERROR
|
||||||
//~^ ERROR
|
//~^ ERROR
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
#[feature(struct_variant)];
|
#[feature(struct_variant)];
|
||||||
extern crate extra;
|
extern crate extra;
|
||||||
|
|
||||||
|
#[deriving(Eq)]
|
||||||
struct Error;
|
struct Error;
|
||||||
|
|
||||||
#[deriving(TotalEq)]
|
#[deriving(Eq, TotalEq)]
|
||||||
enum Enum {
|
enum Enum {
|
||||||
A {
|
A {
|
||||||
x: Error //~ ERROR
|
x: Error //~ ERROR
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
#[feature(struct_variant)];
|
#[feature(struct_variant)];
|
||||||
extern crate extra;
|
extern crate extra;
|
||||||
|
|
||||||
|
#[deriving(Eq)]
|
||||||
struct Error;
|
struct Error;
|
||||||
|
|
||||||
#[deriving(TotalEq)]
|
#[deriving(Eq, TotalEq)]
|
||||||
enum Enum {
|
enum Enum {
|
||||||
A(
|
A(
|
||||||
Error //~ ERROR
|
Error //~ ERROR
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
#[feature(struct_variant)];
|
#[feature(struct_variant)];
|
||||||
extern crate extra;
|
extern crate extra;
|
||||||
|
|
||||||
|
#[deriving(Eq)]
|
||||||
struct Error;
|
struct Error;
|
||||||
|
|
||||||
#[deriving(TotalEq)]
|
#[deriving(Eq, TotalEq)]
|
||||||
struct Struct {
|
struct Struct {
|
||||||
x: Error //~ ERROR
|
x: Error //~ ERROR
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
#[feature(struct_variant)];
|
#[feature(struct_variant)];
|
||||||
extern crate extra;
|
extern crate extra;
|
||||||
|
|
||||||
|
#[deriving(Eq)]
|
||||||
struct Error;
|
struct Error;
|
||||||
|
|
||||||
#[deriving(TotalEq)]
|
#[deriving(Eq, TotalEq)]
|
||||||
struct Struct(
|
struct Struct(
|
||||||
Error //~ ERROR
|
Error //~ ERROR
|
||||||
);
|
);
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
#[feature(struct_variant)];
|
#[feature(struct_variant)];
|
||||||
extern crate extra;
|
extern crate extra;
|
||||||
|
|
||||||
#[deriving(TotalEq)]
|
#[deriving(Eq, Ord, TotalEq)]
|
||||||
struct Error;
|
struct Error;
|
||||||
|
|
||||||
#[deriving(TotalOrd,TotalEq)]
|
#[deriving(Eq, Ord, TotalOrd,TotalEq)]
|
||||||
enum Enum {
|
enum Enum {
|
||||||
A {
|
A {
|
||||||
x: Error //~ ERROR
|
x: Error //~ ERROR
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
#[feature(struct_variant)];
|
#[feature(struct_variant)];
|
||||||
extern crate extra;
|
extern crate extra;
|
||||||
|
|
||||||
#[deriving(TotalEq)]
|
#[deriving(Eq, Ord, TotalEq)]
|
||||||
struct Error;
|
struct Error;
|
||||||
|
|
||||||
#[deriving(TotalOrd,TotalEq)]
|
#[deriving(Eq, Ord, TotalOrd,TotalEq)]
|
||||||
enum Enum {
|
enum Enum {
|
||||||
A(
|
A(
|
||||||
Error //~ ERROR
|
Error //~ ERROR
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
#[feature(struct_variant)];
|
#[feature(struct_variant)];
|
||||||
extern crate extra;
|
extern crate extra;
|
||||||
|
|
||||||
#[deriving(TotalEq)]
|
#[deriving(Eq, Ord, TotalEq)]
|
||||||
struct Error;
|
struct Error;
|
||||||
|
|
||||||
#[deriving(TotalOrd,TotalEq)]
|
#[deriving(Eq, Ord, TotalOrd,TotalEq)]
|
||||||
struct Struct {
|
struct Struct {
|
||||||
x: Error //~ ERROR
|
x: Error //~ ERROR
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
#[feature(struct_variant)];
|
#[feature(struct_variant)];
|
||||||
extern crate extra;
|
extern crate extra;
|
||||||
|
|
||||||
#[deriving(TotalEq)]
|
#[deriving(Eq, Ord, TotalEq)]
|
||||||
struct Error;
|
struct Error;
|
||||||
|
|
||||||
#[deriving(TotalOrd,TotalEq)]
|
#[deriving(Eq, Ord, TotalOrd,TotalEq)]
|
||||||
struct Struct(
|
struct Struct(
|
||||||
Error //~ ERROR
|
Error //~ ERROR
|
||||||
);
|
);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#[deriving(Eq)]
|
||||||
struct thing(uint);
|
struct thing(uint);
|
||||||
impl Ord for thing { //~ ERROR not all trait methods implemented, missing: `lt`
|
impl Ord for thing { //~ ERROR not all trait methods implemented, missing: `lt`
|
||||||
fn le(&self, other: &thing) -> bool { true }
|
fn le(&self, other: &thing) -> bool { true }
|
||||||
|
|
|
@ -22,6 +22,14 @@ impl Eq for Fool {
|
||||||
|
|
||||||
struct Int(int);
|
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 {
|
impl Ord for Int {
|
||||||
fn lt(&self, other: &Int) -> bool {
|
fn lt(&self, other: &Int) -> bool {
|
||||||
let Int(this) = *self;
|
let Int(this) = *self;
|
||||||
|
@ -32,6 +40,14 @@ impl Ord for Int {
|
||||||
|
|
||||||
struct RevInt(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 {
|
impl Ord for RevInt {
|
||||||
fn lt(&self, other: &RevInt) -> bool {
|
fn lt(&self, other: &RevInt) -> bool {
|
||||||
let RevInt(this) = *self;
|
let RevInt(this) = *self;
|
||||||
|
|
|
@ -15,7 +15,7 @@ static MAX_LEN: uint = 20;
|
||||||
static mut drop_counts: [uint, .. MAX_LEN] = [0, .. MAX_LEN];
|
static mut drop_counts: [uint, .. MAX_LEN] = [0, .. MAX_LEN];
|
||||||
static mut clone_count: uint = 0;
|
static mut clone_count: uint = 0;
|
||||||
|
|
||||||
#[deriving(Rand, Ord, TotalEq, TotalOrd)]
|
#[deriving(Rand, Eq, Ord, TotalEq, TotalOrd)]
|
||||||
struct DropCounter { x: uint, clone_num: uint }
|
struct DropCounter { x: uint, clone_num: uint }
|
||||||
|
|
||||||
impl Clone for DropCounter {
|
impl Clone for DropCounter {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue