2012-06-01 17:46:32 -05:00
|
|
|
type point = { x: int, y: int };
|
|
|
|
|
|
|
|
fn a() {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut p = ~[mut 1];
|
2012-06-01 17:46:32 -05:00
|
|
|
|
|
|
|
// Create an immutable pointer into p's contents:
|
2012-06-30 06:23:59 -05:00
|
|
|
let _q: &int = &p[0]; //~ NOTE loan of mutable vec content granted here
|
2012-06-01 17:46:32 -05:00
|
|
|
|
2012-06-30 06:23:59 -05:00
|
|
|
p[0] = 5; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan
|
2012-06-01 17:46:32 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn borrow(_x: &[int], _f: fn()) {}
|
2012-06-01 17:46:32 -05:00
|
|
|
|
|
|
|
fn b() {
|
|
|
|
// here we alias the mutable vector into an imm slice and try to
|
|
|
|
// modify the original:
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut p = ~[mut 1];
|
2012-06-01 17:46:32 -05:00
|
|
|
|
2012-07-02 16:44:31 -05:00
|
|
|
do borrow(p) || { //~ NOTE loan of mutable vec content granted here
|
2012-06-30 06:23:59 -05:00
|
|
|
p[0] = 5; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan
|
2012-06-01 17:46:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn c() {
|
|
|
|
// Legal because the scope of the borrow does not include the
|
|
|
|
// modification:
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut p = ~[mut 1];
|
2012-06-30 18:19:07 -05:00
|
|
|
borrow(p, ||{});
|
2012-06-01 17:46:32 -05:00
|
|
|
p[0] = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|
|
|
|
|