Skip to content

Commit af43127

Browse files
committed
---
yaml --- r: 21263 b: refs/heads/snap-stage3 c: b5411f7 h: refs/heads/master i: 21261: 82cee19 21259: b1cf3d5 21255: 41376de 21247: d1970c8 v: v3
1 parent 030f2d7 commit af43127

File tree

2 files changed

+83
-4
lines changed

2 files changed

+83
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 9b489f6fff4aa07bea2db9457ece5f77c211e016
4+
refs/heads/snap-stage3: b5411f765cdac796fc6798e49521c8da89a394cc
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/managed.rs

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Module for wrapping freezable data structures in managed boxes.
44
Normally freezable data structures require an unaliased reference,
55
such as `T` or `~T`, so that the compiler can track when they are
6-
being mutated. The `rw<T>` type converts these static checks into
6+
being mutated. The `managed<T>` type converts these static checks into
77
dynamic checks: your program will fail if you attempt to perform
88
mutation when the data structure should be immutable.
99
@@ -21,8 +21,8 @@ export Managed;
2121
enum Mode { ReadOnly, Mutable, Immutable }
2222

2323
struct Data<T> {
24-
mut value: T;
25-
mut mode: Mode;
24+
priv mut value: T;
25+
priv mut mode: Mode;
2626
}
2727

2828
type Managed<T> = @Data<T>;
@@ -60,3 +60,82 @@ impl<T> Data<T> {
6060
}
6161
}
6262
}
63+
64+
#[test]
65+
#[should_fail]
66+
fn test_mut_in_imm() {
67+
let m = Managed(1);
68+
do m.borrow_imm |_p| {
69+
do m.borrow_mut |_q| {
70+
// should not be permitted
71+
}
72+
}
73+
}
74+
75+
#[test]
76+
#[should_fail]
77+
fn test_imm_in_mut() {
78+
let m = Managed(1);
79+
do m.borrow_mut |_p| {
80+
do m.borrow_imm |_q| {
81+
// should not be permitted
82+
}
83+
}
84+
}
85+
86+
#[test]
87+
fn test_const_in_mut() {
88+
let m = Managed(1);
89+
do m.borrow_mut |p| {
90+
do m.borrow_const |q| {
91+
assert *p == *q;
92+
*p += 1;
93+
assert *p == *q;
94+
}
95+
}
96+
}
97+
98+
#[test]
99+
fn test_mut_in_const() {
100+
let m = Managed(1);
101+
do m.borrow_const |p| {
102+
do m.borrow_mut |q| {
103+
assert *p == *q;
104+
*q += 1;
105+
assert *p == *q;
106+
}
107+
}
108+
}
109+
110+
#[test]
111+
fn test_imm_in_const() {
112+
let m = Managed(1);
113+
do m.borrow_const |p| {
114+
do m.borrow_imm |q| {
115+
assert *p == *q;
116+
}
117+
}
118+
}
119+
120+
#[test]
121+
fn test_const_in_imm() {
122+
let m = Managed(1);
123+
do m.borrow_imm |p| {
124+
do m.borrow_const |q| {
125+
assert *p == *q;
126+
}
127+
}
128+
}
129+
130+
131+
#[test]
132+
#[should_fail]
133+
fn test_mut_in_imm_in_const() {
134+
let m = Managed(1);
135+
do m.borrow_const |_p| {
136+
do m.borrow_imm |_q| {
137+
do m.borrow_mut |_r| {
138+
}
139+
}
140+
}
141+
}

0 commit comments

Comments
 (0)