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
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@
|
|||
#[feature(struct_variant)];
|
||||
extern crate extra;
|
||||
|
||||
|
||||
#[deriving(Eq)]
|
||||
struct Error;
|
||||
|
||||
#[deriving(Ord)]
|
||||
#[deriving(Eq, Ord)]
|
||||
enum Enum {
|
||||
A(
|
||||
Error //~ ERROR
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@
|
|||
#[feature(struct_variant)];
|
||||
extern crate extra;
|
||||
|
||||
|
||||
#[deriving(Eq)]
|
||||
struct Error;
|
||||
|
||||
#[deriving(Ord)]
|
||||
#[deriving(Eq, Ord)]
|
||||
struct Struct(
|
||||
Error //~ ERROR
|
||||
//~^ ERROR
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@
|
|||
#[feature(struct_variant)];
|
||||
extern crate extra;
|
||||
|
||||
|
||||
#[deriving(Eq)]
|
||||
struct Error;
|
||||
|
||||
#[deriving(TotalEq)]
|
||||
#[deriving(Eq, TotalEq)]
|
||||
enum Enum {
|
||||
A(
|
||||
Error //~ ERROR
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@
|
|||
#[feature(struct_variant)];
|
||||
extern crate extra;
|
||||
|
||||
|
||||
#[deriving(Eq)]
|
||||
struct Error;
|
||||
|
||||
#[deriving(TotalEq)]
|
||||
#[deriving(Eq, TotalEq)]
|
||||
struct Struct {
|
||||
x: Error //~ ERROR
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@
|
|||
#[feature(struct_variant)];
|
||||
extern crate extra;
|
||||
|
||||
|
||||
#[deriving(Eq)]
|
||||
struct Error;
|
||||
|
||||
#[deriving(TotalEq)]
|
||||
#[deriving(Eq, TotalEq)]
|
||||
struct Struct(
|
||||
Error //~ ERROR
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue