librustc: Implement write guards for borrowing @mut to & or &mut. r=nmatsakis
This commit is contained in:
parent
8bde2c1d65
commit
f405e41d7a
38 changed files with 522 additions and 365 deletions
11
src/test/run-fail/write-guard-fail-2.rs
Normal file
11
src/test/run-fail/write-guard-fail-2.rs
Normal 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;
|
||||
}
|
||||
8
src/test/run-fail/write-guard-fail-3.rs
Normal file
8
src/test/run-fail/write-guard-fail-3.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// error-pattern:borrowed
|
||||
|
||||
fn main() {
|
||||
let x = @mut 3;
|
||||
let y: &mut int = x;
|
||||
*x = 5;
|
||||
}
|
||||
|
||||
13
src/test/run-fail/write-guard-fail.rs
Normal file
13
src/test/run-fail/write-guard-fail.rs
Normal 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);
|
||||
}
|
||||
|
||||
9
src/test/run-pass/write-guard.rs
Normal file
9
src/test/run-pass/write-guard.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fn f(x: &int) {
|
||||
io::println(x.to_str());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = @mut 3;
|
||||
f(x);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue