]>
Commit | Line | Data |
---|---|---|
1a4d82fc | 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
223e47cc LB |
2 | // file at the top-level directory of this distribution and at |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
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. | |
10 | ||
1a4d82fc | 11 | |
223e47cc LB |
12 | struct Foo { |
13 | bar1: Bar, | |
14 | bar2: Bar | |
15 | } | |
16 | ||
1a4d82fc JJ |
17 | impl Copy for Foo {} |
18 | ||
223e47cc | 19 | struct Bar { |
1a4d82fc JJ |
20 | int1: isize, |
21 | int2: isize, | |
223e47cc LB |
22 | } |
23 | ||
1a4d82fc JJ |
24 | impl Copy for Bar {} |
25 | ||
26 | fn make_foo() -> Box<Foo> { panic!() } | |
223e47cc LB |
27 | |
28 | fn borrow_same_field_twice_mut_mut() { | |
29 | let mut foo = make_foo(); | |
970d7e83 LB |
30 | let bar1 = &mut foo.bar1; |
31 | let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow | |
32 | *bar1; | |
223e47cc LB |
33 | } |
34 | ||
35 | fn borrow_same_field_twice_mut_imm() { | |
36 | let mut foo = make_foo(); | |
970d7e83 LB |
37 | let bar1 = &mut foo.bar1; |
38 | let _bar2 = &foo.bar1; //~ ERROR cannot borrow | |
39 | *bar1; | |
223e47cc LB |
40 | } |
41 | ||
42 | fn borrow_same_field_twice_imm_mut() { | |
43 | let mut foo = make_foo(); | |
970d7e83 LB |
44 | let bar1 = &foo.bar1; |
45 | let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow | |
46 | *bar1; | |
223e47cc LB |
47 | } |
48 | ||
49 | fn borrow_same_field_twice_imm_imm() { | |
50 | let mut foo = make_foo(); | |
970d7e83 | 51 | let bar1 = &foo.bar1; |
223e47cc | 52 | let _bar2 = &foo.bar1; |
970d7e83 | 53 | *bar1; |
223e47cc LB |
54 | } |
55 | ||
970d7e83 | 56 | fn borrow_both_fields_mut() { |
223e47cc | 57 | let mut foo = make_foo(); |
970d7e83 | 58 | let bar1 = &mut foo.bar1; |
1a4d82fc | 59 | let _bar2 = &mut foo.bar2; //~ ERROR cannot borrow |
970d7e83 | 60 | *bar1; |
223e47cc LB |
61 | } |
62 | ||
63 | fn borrow_both_mut_pattern() { | |
64 | let mut foo = make_foo(); | |
65 | match *foo { | |
66 | Foo { bar1: ref mut _bar1, bar2: ref mut _bar2 } => {} | |
1a4d82fc | 67 | //~^ ERROR cannot borrow |
223e47cc LB |
68 | } |
69 | } | |
70 | ||
71 | fn borrow_var_and_pattern() { | |
72 | let mut foo = make_foo(); | |
970d7e83 | 73 | let bar1 = &mut foo.bar1; |
223e47cc LB |
74 | match *foo { |
75 | Foo { bar1: ref mut _bar1, bar2: _ } => {} | |
970d7e83 | 76 | //~^ ERROR cannot borrow |
223e47cc | 77 | } |
970d7e83 | 78 | *bar1; |
223e47cc LB |
79 | } |
80 | ||
81 | fn borrow_mut_and_base_imm() { | |
82 | let mut foo = make_foo(); | |
970d7e83 LB |
83 | let bar1 = &mut foo.bar1.int1; |
84 | let _foo1 = &foo.bar1; //~ ERROR cannot borrow | |
85 | let _foo2 = &*foo; //~ ERROR cannot borrow | |
86 | *bar1; | |
223e47cc LB |
87 | } |
88 | ||
89 | fn borrow_mut_and_base_mut() { | |
90 | let mut foo = make_foo(); | |
970d7e83 LB |
91 | let bar1 = &mut foo.bar1.int1; |
92 | let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow | |
93 | *bar1; | |
223e47cc LB |
94 | } |
95 | ||
96 | fn borrow_mut_and_base_mut2() { | |
97 | let mut foo = make_foo(); | |
970d7e83 LB |
98 | let bar1 = &mut foo.bar1.int1; |
99 | let _foo2 = &mut *foo; //~ ERROR cannot borrow | |
100 | *bar1; | |
223e47cc LB |
101 | } |
102 | ||
103 | fn borrow_imm_and_base_mut() { | |
104 | let mut foo = make_foo(); | |
970d7e83 LB |
105 | let bar1 = &foo.bar1.int1; |
106 | let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow | |
107 | *bar1; | |
223e47cc LB |
108 | } |
109 | ||
110 | fn borrow_imm_and_base_mut2() { | |
111 | let mut foo = make_foo(); | |
970d7e83 LB |
112 | let bar1 = &foo.bar1.int1; |
113 | let _foo2 = &mut *foo; //~ ERROR cannot borrow | |
114 | *bar1; | |
223e47cc LB |
115 | } |
116 | ||
117 | fn borrow_imm_and_base_imm() { | |
118 | let mut foo = make_foo(); | |
970d7e83 | 119 | let bar1 = &foo.bar1.int1; |
223e47cc LB |
120 | let _foo1 = &foo.bar1; |
121 | let _foo2 = &*foo; | |
970d7e83 | 122 | *bar1; |
223e47cc LB |
123 | } |
124 | ||
125 | fn borrow_mut_and_imm() { | |
126 | let mut foo = make_foo(); | |
970d7e83 | 127 | let bar1 = &mut foo.bar1; |
1a4d82fc | 128 | let _foo1 = &foo.bar2; //~ ERROR cannot borrow |
970d7e83 | 129 | *bar1; |
223e47cc LB |
130 | } |
131 | ||
132 | fn borrow_mut_from_imm() { | |
133 | let foo = make_foo(); | |
970d7e83 LB |
134 | let bar1 = &mut foo.bar1; //~ ERROR cannot borrow |
135 | *bar1; | |
223e47cc LB |
136 | } |
137 | ||
138 | fn borrow_long_path_both_mut() { | |
139 | let mut foo = make_foo(); | |
970d7e83 | 140 | let bar1 = &mut foo.bar1.int1; |
1a4d82fc | 141 | let foo1 = &mut foo.bar2.int2; //~ ERROR cannot borrow |
970d7e83 LB |
142 | *bar1; |
143 | *foo1; | |
223e47cc LB |
144 | } |
145 | ||
146 | fn main() {} |