librustc: Implement write guards for borrowing @mut to & or &mut. r=nmatsakis

This commit is contained in:
Patrick Walton 2013-01-11 21:01:42 -08:00
parent 8bde2c1d65
commit f405e41d7a
38 changed files with 522 additions and 365 deletions

View file

@ -0,0 +1,11 @@
// error-pattern:borrowed
struct S {
x: int
}
fn main() {
let x = @mut S { x: 3 };
let y: &S = x;
x.x = 5;
}

View file

@ -0,0 +1,8 @@
// error-pattern:borrowed
fn main() {
let x = @mut 3;
let y: &mut int = x;
*x = 5;
}

View file

@ -0,0 +1,13 @@
// error-pattern:borrowed
fn f(x: &int, y: @mut int) {
unsafe {
*y = 2;
}
}
fn main() {
let x = @mut 3;
f(x, x);
}

View file

@ -0,0 +1,9 @@
fn f(x: &int) {
io::println(x.to_str());
}
fn main() {
let x = @mut 3;
f(x);
}