DSTify Box<T> implementation of PartialEq, PartialOrd, Eq, Ord
This commit is contained in:
parent
1e5f311d16
commit
4c3b42271b
@ -61,12 +61,16 @@ impl<T: Clone> Clone for Box<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(stage0): remove impl after a snapshot
|
||||
#[cfg(stage0)]
|
||||
impl<T:PartialEq> PartialEq for Box<T> {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Box<T>) -> bool { *(*self) == *(*other) }
|
||||
#[inline]
|
||||
fn ne(&self, other: &Box<T>) -> bool { *(*self) != *(*other) }
|
||||
}
|
||||
// NOTE(stage0): remove impl after a snapshot
|
||||
#[cfg(stage0)]
|
||||
impl<T:PartialOrd> PartialOrd for Box<T> {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Box<T>) -> Option<Ordering> {
|
||||
@ -81,14 +85,50 @@ impl<T:PartialOrd> PartialOrd for Box<T> {
|
||||
#[inline]
|
||||
fn gt(&self, other: &Box<T>) -> bool { *(*self) > *(*other) }
|
||||
}
|
||||
// NOTE(stage0): remove impl after a snapshot
|
||||
#[cfg(stage0)]
|
||||
impl<T: Ord> Ord for Box<T> {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &Box<T>) -> Ordering {
|
||||
(**self).cmp(&**other)
|
||||
}
|
||||
}
|
||||
// NOTE(stage0): remove impl after a snapshot
|
||||
#[cfg(stage0)]
|
||||
impl<T: Eq> Eq for Box<T> {}
|
||||
|
||||
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
|
||||
impl<Sized? T: PartialEq> PartialEq for Box<T> {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Box<T>) -> bool { PartialEq::eq(&**self, &**other) }
|
||||
#[inline]
|
||||
fn ne(&self, other: &Box<T>) -> bool { PartialEq::ne(&**self, &**other) }
|
||||
}
|
||||
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
|
||||
impl<Sized? T: PartialOrd> PartialOrd for Box<T> {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Box<T>) -> Option<Ordering> {
|
||||
PartialOrd::partial_cmp(&**self, &**other)
|
||||
}
|
||||
#[inline]
|
||||
fn lt(&self, other: &Box<T>) -> bool { PartialOrd::lt(&**self, &**other) }
|
||||
#[inline]
|
||||
fn le(&self, other: &Box<T>) -> bool { PartialOrd::le(&**self, &**other) }
|
||||
#[inline]
|
||||
fn ge(&self, other: &Box<T>) -> bool { PartialOrd::ge(&**self, &**other) }
|
||||
#[inline]
|
||||
fn gt(&self, other: &Box<T>) -> bool { PartialOrd::gt(&**self, &**other) }
|
||||
}
|
||||
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
|
||||
impl<Sized? T: Ord> Ord for Box<T> {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &Box<T>) -> Ordering {
|
||||
Ord::cmp(&**self, &**other)
|
||||
}
|
||||
}
|
||||
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
|
||||
impl<Sized? T: Eq> Eq for Box<T> {}
|
||||
|
||||
/// Extension methods for an owning `Any` trait object.
|
||||
#[unstable = "post-DST and coherence changes, this will not be a trait but \
|
||||
rather a direct `impl` on `Box<Any>`"]
|
||||
|
24
src/test/run-pass/deriving-eq-ord-boxed-slice.rs
Normal file
24
src/test/run-pass/deriving-eq-ord-boxed-slice.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[deriving(PartialEq, PartialOrd, Eq, Ord)]
|
||||
struct Foo(Box<[u8]>);
|
||||
|
||||
pub fn main() {
|
||||
let a = Foo(box [0, 1, 2]);
|
||||
let b = Foo(box [0, 1, 2]);
|
||||
assert!(a == b);
|
||||
println!("{}", a != b);
|
||||
println!("{}", a < b);
|
||||
println!("{}", a <= b);
|
||||
println!("{}", a == b);
|
||||
println!("{}", a > b);
|
||||
println!("{}", a >= b);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user