1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 //[mir]compile-flags: -Z borrowck=mir
14 fn borrow_mut<T>(x: &mut T) -> &mut T { x }
15 fn borrow<T>(x: &T) -> &T { x }
17 fn borrow_mut2<T>(_: &mut T, _: &mut T) {}
18 fn borrow2<T>(_: &mut T, _: &T) {}
20 fn double_mut_borrow<T>(x: &mut Box<T>) {
21 let y = borrow_mut(x);
22 let z = borrow_mut(x);
23 //[ast]~^ ERROR cannot borrow `*x` as mutable more than once at a time
24 //[mir]~^^ ERROR cannot borrow `*x` as mutable more than once at a time
28 fn double_imm_borrow(x: &mut Box<i32>) {
32 //[ast]~^ ERROR cannot assign to `**x` because it is borrowed
33 //[mir]~^^ ERROR cannot assign to `**x` because it is borrowed
37 fn double_mut_borrow2<T>(x: &mut Box<T>) {
39 //[ast]~^ ERROR cannot borrow `*x` as mutable more than once at a time
40 //[mir]~^^ ERROR cannot borrow `*x` as mutable more than once at a time
43 fn double_borrow2<T>(x: &mut Box<T>) {
45 //[ast]~^ ERROR cannot borrow `*x` as immutable because it is also borrowed as mutable
46 //[mir]~^^ ERROR cannot borrow `*x` as immutable because it is also borrowed as mutable