diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2013-05-05 21:05:37 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2013-05-05 21:05:37 -0400 |
| commit | 7b36e34c89372b4a159d4ad565ce11d412fbea04 (patch) | |
| tree | ee0aa9d8caec48bf6105270613a402bb2696d162 /src/test | |
| parent | 4300d4d2fa9d35ac73742c7d815ee157ce0f9c17 (diff) | |
Fix two more write guard failures
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-fail/borrowck-wg-imm-then-mut.rs | 19 | ||||
| -rw-r--r-- | src/test/run-fail/borrowck-wg-mut-then-imm.rs | 19 | ||||
| -rw-r--r-- | src/test/run-pass/regions-mock-trans-impls.rs | 54 |
3 files changed, 38 insertions, 54 deletions
diff --git a/src/test/run-fail/borrowck-wg-imm-then-mut.rs b/src/test/run-fail/borrowck-wg-imm-then-mut.rs new file mode 100644 index 00000000000..e2c8a0b549c --- /dev/null +++ b/src/test/run-fail/borrowck-wg-imm-then-mut.rs @@ -0,0 +1,19 @@ +// error-pattern:borrowed + +// Test that if you imm borrow then mut borrow it fails. + +fn add1(a:@mut int) +{ + add2(a); // already frozen +} + +fn add2(_:&mut int) +{ +} + +pub fn main() +{ + let a = @mut 3; + let b = &*a; // freezes a + add1(a); +} diff --git a/src/test/run-fail/borrowck-wg-mut-then-imm.rs b/src/test/run-fail/borrowck-wg-mut-then-imm.rs new file mode 100644 index 00000000000..58b2a1d87be --- /dev/null +++ b/src/test/run-fail/borrowck-wg-mut-then-imm.rs @@ -0,0 +1,19 @@ +// error-pattern:borrowed + +// Test that if you mut borrow then imm borrow it fails. + +fn add1(a:@mut int) +{ + add2(a); // already frozen +} + +fn add2(_:&int) +{ +} + +pub fn main() +{ + let a = @mut 3; + let b = &mut *a; // freezes a + add1(a); +} diff --git a/src/test/run-pass/regions-mock-trans-impls.rs b/src/test/run-pass/regions-mock-trans-impls.rs deleted file mode 100644 index d54aae7bb63..00000000000 --- a/src/test/run-pass/regions-mock-trans-impls.rs +++ /dev/null @@ -1,54 +0,0 @@ -// xfail-fast - -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -extern mod std; -use core::libc; -use core::sys; -use core::cast; -use std::arena::Arena; - -struct Bcx<'self> { - fcx: &'self Fcx<'self> -} - -struct Fcx<'self> { - arena: &'self mut Arena, - ccx: &'self Ccx -} - -struct Ccx { - x: int -} - -fn h<'r>(bcx : &'r mut Bcx<'r>) -> &'r mut Bcx<'r> { - // XXX: Arena has a bad interface here; it should return mutable pointers. - // But this patch is too big to roll that in. - unsafe { - cast::transmute(bcx.fcx.arena.alloc(|| Bcx { fcx: bcx.fcx })) - } -} - -fn g(fcx: &mut Fcx) { - let mut bcx = Bcx { fcx: fcx }; - h(&mut bcx); -} - -fn f(ccx: &mut Ccx) { - let mut a = Arena(); - let mut fcx = Fcx { arena: &mut a, ccx: ccx }; - return g(&mut fcx); -} - -pub fn main() { - let mut ccx = Ccx { x: 0 }; - f(&mut ccx); -} |
