Skip to content

Commit 4c3b422

Browse files
author
Jorge Aparicio
committed
DSTify Box<T> implementation of PartialEq, PartialOrd, Eq, Ord
1 parent 1e5f311 commit 4c3b422

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

src/liballoc/boxed.rs

+40
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ impl<T: Clone> Clone for Box<T> {
6161
}
6262
}
6363

64+
// NOTE(stage0): remove impl after a snapshot
65+
#[cfg(stage0)]
6466
impl<T:PartialEq> PartialEq for Box<T> {
6567
#[inline]
6668
fn eq(&self, other: &Box<T>) -> bool { *(*self) == *(*other) }
6769
#[inline]
6870
fn ne(&self, other: &Box<T>) -> bool { *(*self) != *(*other) }
6971
}
72+
// NOTE(stage0): remove impl after a snapshot
73+
#[cfg(stage0)]
7074
impl<T:PartialOrd> PartialOrd for Box<T> {
7175
#[inline]
7276
fn partial_cmp(&self, other: &Box<T>) -> Option<Ordering> {
@@ -81,14 +85,50 @@ impl<T:PartialOrd> PartialOrd for Box<T> {
8185
#[inline]
8286
fn gt(&self, other: &Box<T>) -> bool { *(*self) > *(*other) }
8387
}
88+
// NOTE(stage0): remove impl after a snapshot
89+
#[cfg(stage0)]
8490
impl<T: Ord> Ord for Box<T> {
8591
#[inline]
8692
fn cmp(&self, other: &Box<T>) -> Ordering {
8793
(**self).cmp(&**other)
8894
}
8995
}
96+
// NOTE(stage0): remove impl after a snapshot
97+
#[cfg(stage0)]
9098
impl<T: Eq> Eq for Box<T> {}
9199

100+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
101+
impl<Sized? T: PartialEq> PartialEq for Box<T> {
102+
#[inline]
103+
fn eq(&self, other: &Box<T>) -> bool { PartialEq::eq(&**self, &**other) }
104+
#[inline]
105+
fn ne(&self, other: &Box<T>) -> bool { PartialEq::ne(&**self, &**other) }
106+
}
107+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
108+
impl<Sized? T: PartialOrd> PartialOrd for Box<T> {
109+
#[inline]
110+
fn partial_cmp(&self, other: &Box<T>) -> Option<Ordering> {
111+
PartialOrd::partial_cmp(&**self, &**other)
112+
}
113+
#[inline]
114+
fn lt(&self, other: &Box<T>) -> bool { PartialOrd::lt(&**self, &**other) }
115+
#[inline]
116+
fn le(&self, other: &Box<T>) -> bool { PartialOrd::le(&**self, &**other) }
117+
#[inline]
118+
fn ge(&self, other: &Box<T>) -> bool { PartialOrd::ge(&**self, &**other) }
119+
#[inline]
120+
fn gt(&self, other: &Box<T>) -> bool { PartialOrd::gt(&**self, &**other) }
121+
}
122+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
123+
impl<Sized? T: Ord> Ord for Box<T> {
124+
#[inline]
125+
fn cmp(&self, other: &Box<T>) -> Ordering {
126+
Ord::cmp(&**self, &**other)
127+
}
128+
}
129+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
130+
impl<Sized? T: Eq> Eq for Box<T> {}
131+
92132
/// Extension methods for an owning `Any` trait object.
93133
#[unstable = "post-DST and coherence changes, this will not be a trait but \
94134
rather a direct `impl` on `Box<Any>`"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[deriving(PartialEq, PartialOrd, Eq, Ord)]
12+
struct Foo(Box<[u8]>);
13+
14+
pub fn main() {
15+
let a = Foo(box [0, 1, 2]);
16+
let b = Foo(box [0, 1, 2]);
17+
assert!(a == b);
18+
println!("{}", a != b);
19+
println!("{}", a < b);
20+
println!("{}", a <= b);
21+
println!("{}", a == b);
22+
println!("{}", a > b);
23+
println!("{}", a >= b);
24+
}

0 commit comments

Comments
 (0)