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.
26 fn make_foo() -> Box
<Foo
> { panic!() }
28 fn borrow_same_field_twice_mut_mut() {
29 let mut foo
= make_foo();
30 let bar1
= &mut foo
.bar1
;
31 let _bar2
= &mut foo
.bar1
; //~ ERROR cannot borrow
35 fn borrow_same_field_twice_mut_imm() {
36 let mut foo
= make_foo();
37 let bar1
= &mut foo
.bar1
;
38 let _bar2
= &foo
.bar1
; //~ ERROR cannot borrow
42 fn borrow_same_field_twice_imm_mut() {
43 let mut foo
= make_foo();
45 let _bar2
= &mut foo
.bar1
; //~ ERROR cannot borrow
49 fn borrow_same_field_twice_imm_imm() {
50 let mut foo
= make_foo();
52 let _bar2
= &foo
.bar1
;
56 fn borrow_both_fields_mut() {
57 let mut foo
= make_foo();
58 let bar1
= &mut foo
.bar1
;
59 let _bar2
= &mut foo
.bar2
; //~ ERROR cannot borrow
63 fn borrow_both_mut_pattern() {
64 let mut foo
= make_foo();
66 Foo { bar1: ref mut _bar1, bar2: ref mut _bar2 }
=> {}
67 //~^ ERROR cannot borrow
71 fn borrow_var_and_pattern() {
72 let mut foo
= make_foo();
73 let bar1
= &mut foo
.bar1
;
75 Foo { bar1: ref mut _bar1, bar2: _ }
=> {}
76 //~^ ERROR cannot borrow
81 fn borrow_mut_and_base_imm() {
82 let mut foo
= make_foo();
83 let bar1
= &mut foo
.bar1
.int1
;
84 let _foo1
= &foo
.bar1
; //~ ERROR cannot borrow
85 let _foo2
= &*foo
; //~ ERROR cannot borrow
89 fn borrow_mut_and_base_mut() {
90 let mut foo
= make_foo();
91 let bar1
= &mut foo
.bar1
.int1
;
92 let _foo1
= &mut foo
.bar1
; //~ ERROR cannot borrow
96 fn borrow_mut_and_base_mut2() {
97 let mut foo
= make_foo();
98 let bar1
= &mut foo
.bar1
.int1
;
99 let _foo2
= &mut *foo
; //~ ERROR cannot borrow
103 fn borrow_imm_and_base_mut() {
104 let mut foo
= make_foo();
105 let bar1
= &foo
.bar1
.int1
;
106 let _foo1
= &mut foo
.bar1
; //~ ERROR cannot borrow
110 fn borrow_imm_and_base_mut2() {
111 let mut foo
= make_foo();
112 let bar1
= &foo
.bar1
.int1
;
113 let _foo2
= &mut *foo
; //~ ERROR cannot borrow
117 fn borrow_imm_and_base_imm() {
118 let mut foo
= make_foo();
119 let bar1
= &foo
.bar1
.int1
;
120 let _foo1
= &foo
.bar1
;
125 fn borrow_mut_and_imm() {
126 let mut foo
= make_foo();
127 let bar1
= &mut foo
.bar1
;
128 let _foo1
= &foo
.bar2
; //~ ERROR cannot borrow
132 fn borrow_mut_from_imm() {
133 let foo
= make_foo();
134 let bar1
= &mut foo
.bar1
; //~ ERROR cannot borrow
138 fn borrow_long_path_both_mut() {
139 let mut foo
= make_foo();
140 let bar1
= &mut foo
.bar1
.int1
;
141 let foo1
= &mut foo
.bar2
.int2
; //~ ERROR cannot borrow