Skip to content

Commit ca52d08

Browse files
committed
Removed mut-fields from Mut, removed borrow_const from Mut
1 parent 00dbbd0 commit ca52d08

File tree

1 file changed

+7
-70
lines changed

1 file changed

+7
-70
lines changed

src/libcore/mutable.rs

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ mutation when the data structure should be immutable.
2020
*/
2121

2222
use util::with;
23-
use cast::transmute_immut;
23+
use cast::{transmute_mut,transmute_immut};
2424

2525
enum Mode { ReadOnly, Mutable, Immutable }
2626

2727
struct Data<T> {
28-
priv mut value: T,
29-
priv mut mode: Mode
28+
priv value: T,
29+
priv mode: Mode
3030
}
3131

3232
pub type Mut<T> = Data<T>;
@@ -50,23 +50,19 @@ pub impl<T> Data<T> {
5050
ReadOnly | Mutable => {}
5151
}
5252
53-
do with(&mut self.mode, Mutable) {
54-
op(&mut self.value)
53+
do with( unsafe { transmute_mut(&self.mode) }, Mutable) {
54+
op( unsafe { transmute_mut(&self.value) })
5555
}
5656
}
5757
58-
fn borrow_const<R>(&self, op: &fn(t: &const T) -> R) -> R {
59-
op(&const self.value)
60-
}
61-
6258
fn borrow_imm<R>(&self, op: &fn(t: &T) -> R) -> R {
6359
match self.mode {
6460
Mutable => fail!(~"currently mutable"),
6561
ReadOnly | Immutable => {}
6662
}
6763

68-
do with(&mut self.mode, Immutable) {
69-
op(unsafe{transmute_immut(&mut self.value)})
64+
do with( unsafe { transmute_mut(&self.mode) }, Immutable) {
65+
op( &self.value )
7066
}
7167
}
7268

@@ -97,62 +93,3 @@ pub fn test_imm_in_mut() {
9793
}
9894
}
9995
}
100-
101-
#[test]
102-
pub fn test_const_in_mut() {
103-
let m = @Mut(1);
104-
do m.borrow_mut |p| {
105-
do m.borrow_const |q| {
106-
assert!(*p == *q);
107-
*p += 1;
108-
assert!(*p == *q);
109-
}
110-
}
111-
}
112-
113-
#[test]
114-
pub fn test_mut_in_const() {
115-
let m = @Mut(1);
116-
do m.borrow_const |p| {
117-
do m.borrow_mut |q| {
118-
assert!(*p == *q);
119-
*q += 1;
120-
assert!(*p == *q);
121-
}
122-
}
123-
}
124-
125-
#[test]
126-
pub fn test_imm_in_const() {
127-
let m = @Mut(1);
128-
do m.borrow_const |p| {
129-
do m.borrow_imm |q| {
130-
assert!(*p == *q);
131-
}
132-
}
133-
}
134-
135-
#[test]
136-
pub fn test_const_in_imm() {
137-
let m = @Mut(1);
138-
do m.borrow_imm |p| {
139-
do m.borrow_const |q| {
140-
assert!(*p == *q);
141-
}
142-
}
143-
}
144-
145-
146-
#[test]
147-
#[ignore(cfg(windows))]
148-
#[should_fail]
149-
pub fn test_mut_in_imm_in_const() {
150-
let m = @Mut(1);
151-
do m.borrow_const |_p| {
152-
do m.borrow_imm |_q| {
153-
do m.borrow_mut |_r| {
154-
}
155-
}
156-
}
157-
}
158-

0 commit comments

Comments
 (0)