17 fn x(&mut self) -> &mut u32 { &mut self.x }
21 fn x(&mut self) -> &mut u32 { &mut self.0 }
25 fn x(&mut self) -> &mut u32 {
27 Baz::X(ref mut value) => value
33 // Local and field from struct
35 let mut f = Foo { x: 22 };
37 f.x; //~ ERROR cannot use `f.x` because it was mutably borrowed
40 // Local and field from tuple-struct
44 g.0; //~ ERROR cannot use `g.0` because it was mutably borrowed
47 // Local and field from tuple
51 h.0; //~ ERROR cannot use `h.0` because it was mutably borrowed
54 // Local and field from enum
56 let mut e = Baz::X(2);
59 Baz::X(value) => value //~ ERROR cannot use `e.0` because it was mutably borrowed
63 // Local and field from union
65 let mut u = U { b: 0 };
67 u.a; //~ ERROR cannot use `u.a` because it was mutably borrowed
70 // Deref and field from struct
72 let mut f = Box::new(Foo { x: 22 });
74 f.x; //~ ERROR cannot use `f.x` because it was mutably borrowed
77 // Deref and field from tuple-struct
79 let mut g = Box::new(Bar(22));
81 g.0; //~ ERROR cannot use `g.0` because it was mutably borrowed
84 // Deref and field from tuple
86 let mut h = Box::new((22, 23));
88 h.0; //~ ERROR cannot use `h.0` because it was mutably borrowed
91 // Deref and field from enum
93 let mut e = Box::new(Baz::X(3));
96 Baz::X(value) => value
97 //~^ ERROR cannot use `e.0` because it was mutably borrowed
101 // Deref and field from union
103 let mut u = Box::new(U { b: 0 });
105 u.a; //~ ERROR cannot use `u.a` because it was mutably borrowed
110 let mut v = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
113 &[x, _, .., _, _] => println!("{}", x),
114 //~^ ERROR cannot use `v[..]` because it was mutably borrowed
115 _ => panic!("other case"),
118 &[_, x, .., _, _] => println!("{}", x),
119 //~^ ERROR cannot use `v[..]` because it was mutably borrowed
120 _ => panic!("other case"),
123 &[_, _, .., x, _] => println!("{}", x),
124 //~^ ERROR cannot use `v[..]` because it was mutably borrowed
125 _ => panic!("other case"),
128 &[_, _, .., _, x] => println!("{}", x),
129 //~^ ERROR cannot use `v[..]` because it was mutably borrowed
130 _ => panic!("other case"),
136 let mut v = &[1, 2, 3, 4, 5];
139 &[x @ ..] => println!("{:?}", x),
140 //~^ ERROR cannot use `v[..]` because it was mutably borrowed
141 _ => panic!("other case"),
144 &[_, x @ ..] => println!("{:?}", x),
145 //~^ ERROR cannot use `v[..]` because it was mutably borrowed
146 _ => panic!("other case"),
149 &[x @ .., _] => println!("{:?}", x),
150 //~^ ERROR cannot use `v[..]` because it was mutably borrowed
151 _ => panic!("other case"),
154 &[_, x @ .., _] => println!("{:?}", x),
155 //~^ ERROR cannot use `v[..]` because it was mutably borrowed
156 _ => panic!("other case"),
162 enum E<X> { A(X), B { x: X } }
167 //~^ ERROR cannot use `e` because it was mutably borrowed
169 //~^ ERROR cannot borrow `e.0` as immutable because it is also borrowed as mutable
170 println!("e.ax: {:?}", ax),
171 E::B { x: ref bx } =>
172 //~^ ERROR cannot borrow `e.x` as immutable because it is also borrowed as mutable
173 println!("e.bx: {:?}", bx),
179 struct F { x: u32, y: u32 };
180 struct S { x: F, y: (u32, u32), };
181 let mut s = S { x: F { x: 1, y: 2}, y: (999, 998) };
184 S { y: (ref y0, _), .. } =>
185 //~^ ERROR cannot borrow `s.y.0` as immutable because it is also borrowed as mutable
186 println!("y0: {:?}", y0),
187 _ => panic!("other case"),
190 S { x: F { y: ref x0, .. }, .. } =>
191 //~^ ERROR cannot borrow `s.x.y` as immutable because it is also borrowed as mutable
192 println!("x0: {:?}", x0),
193 _ => panic!("other case"),
204 fn bump<'a>(mut block: &mut Block<'a>) {
206 let p: &'a u8 = &*block.current;
207 //~^ ERROR cannot borrow `*block.current` as immutable because it is also borrowed as mutable
208 // See issue rust#38899
216 unrelated: *const u8,
219 unsafe fn bump2(mut block: *mut Block2) {
221 let p : *const u8 = &*(*block).current;
222 //~^ ERROR cannot borrow `*block.current` as immutable because it is also borrowed as mutable
223 // See issue rust#38899
229 struct F {x: u32, y: u32};
230 let mut v = &[F{x: 1, y: 2}, F{x: 3, y: 4}];
233 //~^ ERROR cannot use `v[_].y` because it was mutably borrowed
234 //~| ERROR cannot use `*v` because it was mutably borrowed
237 // Field of constant index
239 struct F {x: u32, y: u32};
240 let mut v = &[F{x: 1, y: 2}, F{x: 3, y: 4}];
243 &[_, F {x: ref xf, ..}] => println!("{}", xf),
244 //~^ ERROR cannot borrow `v[..].x` as immutable because it is also borrowed as mutable
245 _ => panic!("other case")
254 &mut x; //~ ERROR cannot borrow `x` as mutable more than once at a time
258 // Field from upvar nested
262 || { //~ ERROR captured variable cannot escape `FnMut` closure body
264 &mut x; //~ ERROR cannot borrow `x` as mutable more than once at a time
271 fn foo(x: Vec<i32>) {
274 drop(x); //~ ERROR use of moved value: `x`