Skip to content

Commit 5b38798

Browse files
committed
---
yaml --- r: 29971 b: refs/heads/incoming c: b5411f7 h: refs/heads/master i: 29969: e677ac3 29967: e0bd85d v: v3
1 parent 6fdcf71 commit 5b38798

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
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 9b489f6fff4aa07bea2db9457ece5f77c211e016
9+
refs/heads/incoming: b5411f765cdac796fc6798e49521c8da89a394cc
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

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