Skip to content

Commit af307bd

Browse files
committed
---
yaml --- r: 139519 b: refs/heads/try2 c: ca52d08 h: refs/heads/master i: 139517: 1cb037f 139515: f08c842 139511: 62c6ad2 139503: 3c43485 139487: 5a0c672 139455: 4020044 139391: fb42803 139263: 8878be9 v: v3
1 parent fb27439 commit af307bd

File tree

2 files changed

+8
-71
lines changed

2 files changed

+8
-71
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 00dbbd01c2aee72982b3e0f9511ae1d4428c3ba9
8+
refs/heads/try2: ca52d08c4b62a8e501387d305eea1ccccaeb3984
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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)