Implement RFC#28: Add PartialOrd::partial_cmp
I ended up altering the semantics of Json's PartialOrd implementation. It used to be the case that Null < Null, but I can't think of any reason for an ordering other than the default one so I just switched it over to using the derived implementation. This also fixes broken `PartialOrd` implementations for `Vec` and `TreeMap`. RFC: 0028-partial-cmp
This commit is contained in:
parent
bb5695b95c
commit
55cae0a094
28 changed files with 343 additions and 161 deletions
|
|
@ -27,6 +27,7 @@ enum Enum {
|
|||
//~^^^^^ ERROR
|
||||
//~^^^^^^ ERROR
|
||||
//~^^^^^^^ ERROR
|
||||
//~^^^^^^^^ ERROR
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ enum Enum {
|
|||
//~^^^^^ ERROR
|
||||
//~^^^^^^ ERROR
|
||||
//~^^^^^^^ ERROR
|
||||
//~^^^^^^^^ ERROR
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ struct Struct {
|
|||
//~^^^^^ ERROR
|
||||
//~^^^^^^ ERROR
|
||||
//~^^^^^^^ ERROR
|
||||
//~^^^^^^^^ ERROR
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ struct Struct(
|
|||
//~^^^^^ ERROR
|
||||
//~^^^^^^ ERROR
|
||||
//~^^^^^^^ ERROR
|
||||
//~^^^^^^^^ ERROR
|
||||
);
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#[deriving(PartialEq)]
|
||||
struct thing(uint);
|
||||
impl PartialOrd for thing { //~ ERROR not all trait methods implemented, missing: `lt`
|
||||
impl PartialOrd for thing { //~ ERROR not all trait methods implemented, missing: `partial_cmp`
|
||||
fn le(&self, other: &thing) -> bool { true }
|
||||
fn ge(&self, other: &thing) -> bool { true }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ impl PartialEq for Int {
|
|||
}
|
||||
|
||||
impl PartialOrd for Int {
|
||||
fn lt(&self, other: &Int) -> bool {
|
||||
fn partial_cmp(&self, other: &Int) -> Option<Ordering> {
|
||||
let Int(this) = *self;
|
||||
let Int(other) = *other;
|
||||
this < other
|
||||
this.partial_cmp(&other)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,10 +49,10 @@ impl PartialEq for RevInt {
|
|||
}
|
||||
|
||||
impl PartialOrd for RevInt {
|
||||
fn lt(&self, other: &RevInt) -> bool {
|
||||
fn partial_cmp(&self, other: &RevInt) -> Option<Ordering> {
|
||||
let RevInt(this) = *self;
|
||||
let RevInt(other) = *other;
|
||||
this > other
|
||||
other.partial_cmp(&this)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ impl PartialEq for FailCmp {
|
|||
}
|
||||
|
||||
impl PartialOrd for FailCmp {
|
||||
fn lt(&self, _: &FailCmp) -> bool { fail!("lt") }
|
||||
fn partial_cmp(&self, _: &FailCmp) -> Option<Ordering> { fail!("partial_cmp") }
|
||||
}
|
||||
|
||||
impl Eq for FailCmp {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue