Skip to content

Commit a6b9fa0

Browse files
committed
new test for loaning out an index
1 parent 63eb8e0 commit a6b9fa0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// compile-flags:--borrowck=err
2+
3+
// Here we check that it is allowed to lend out an element of a
4+
// (locally rooted) mutable, unique vector, and that we then prevent
5+
// modifications to the contents.
6+
7+
fn takes_imm_elt(_v: &int, f: fn()) {
8+
f();
9+
}
10+
11+
fn has_mut_vec_and_does_not_try_to_change_it() {
12+
let v = [mut 1, 2, 3];
13+
takes_imm_elt(&v[0]) {||
14+
}
15+
}
16+
17+
fn has_mut_vec_but_tries_to_change_it() {
18+
let v = [mut 1, 2, 3];
19+
takes_imm_elt(&v[0]) {|| //! NOTE loan of mutable vec content granted here
20+
v[1] = 4; //! ERROR assigning to mutable vec content prohibited due to outstanding loan
21+
}
22+
}
23+
24+
fn takes_const_elt(_v: &const int, f: fn()) {
25+
f();
26+
}
27+
28+
fn has_mut_vec_and_tries_to_change_it() {
29+
let v = [mut 1, 2, 3];
30+
takes_const_elt(&const v[0]) {||
31+
v[1] = 4;
32+
}
33+
}
34+
35+
fn main() {
36+
}

0 commit comments

Comments
 (0)