Skip to content

Commit cda3ac9

Browse files
committed
rc: fix tests
1 parent 75822f2 commit cda3ac9

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

src/libcore/cell.rs

+7
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ Similar to a mutable option type, but friendlier.
2121
*/
2222

2323
#[mutable]
24+
#[deriving(Clone)]
2425
pub struct Cell<T> {
2526
priv value: Option<T>
2627
}
2728

29+
impl<T: DeepClone> DeepClone for Cell<T> {
30+
fn deep_clone(&self) -> Cell<T> {
31+
Cell{value: self.value.deep_clone()}
32+
}
33+
}
34+
2835
impl<T:cmp::Eq> cmp::Eq for Cell<T> {
2936
fn eq(&self, other: &Cell<T>) -> bool {
3037
(self.value) == (other.value)

src/libcore/option.rs

+10
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use num::Zero;
4949
use old_iter::{BaseIter, MutableIter, ExtendedIter};
5050
use old_iter;
5151
use str::StrSlice;
52+
use clone::DeepClone;
5253

5354
#[cfg(test)] use str;
5455

@@ -59,6 +60,15 @@ pub enum Option<T> {
5960
Some(T),
6061
}
6162

63+
impl<T: DeepClone> DeepClone for Option<T> {
64+
fn deep_clone(&self) -> Option<T> {
65+
match *self {
66+
Some(ref x) => Some(x.deep_clone()),
67+
None => None
68+
}
69+
}
70+
}
71+
6272
impl<T:Ord> Ord for Option<T> {
6373
fn lt(&self, other: &Option<T>) -> bool {
6474
match (self, other) {

src/libstd/rc.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,20 @@ mod test_rc {
103103
fn test_clone() {
104104
let x = Rc::new(Cell(5));
105105
let y = x.clone();
106-
do x.with_borrow |cell| {
107-
do value.with_mut_ref |inner| {
108-
*inner = 20;
109-
}
110-
}
111-
do y.with_borrow |value| {
112-
assert_eq!(value.take(), 20);
106+
do x.borrow().with_mut_ref |inner| {
107+
*inner = 20;
113108
}
109+
assert_eq!(y.borrow().take(), 20);
114110
}
115111

116112
#[test]
117113
fn test_deep_clone() {
118114
let x = Rc::new(Cell(5));
119115
let y = x.deep_clone();
120-
do x.with_borrow |cell| {
121-
do value.with_mut_ref |inner| {
122-
*inner = 20;
123-
}
124-
}
125-
do y.with_borrow |value| {
126-
assert_eq!(value.take(), 5);
116+
do x.borrow().with_mut_ref |inner| {
117+
*inner = 20;
127118
}
119+
assert_eq!(y.borrow().take(), 5);
128120
}
129121

130122
#[test]
@@ -134,7 +126,7 @@ mod test_rc {
134126
}
135127

136128
#[test]
137-
fn test_clone() {
129+
fn test_simple_clone() {
138130
let x = Rc::new(5);
139131
let y = x.clone();
140132
assert_eq!(*x.borrow(), 5);

0 commit comments

Comments
 (0)