1 pub enum X {
2     Y
3 }
4 
5 pub struct Z {
6     x: X
7 }
8 
main()9 fn main() {
10     let z = Z { x: X::Y };
11     let _ = &mut z.x; //~ ERROR cannot borrow
12 }
13 
14 impl Z {
foo<'z>(&'z self)15     fn foo<'z>(&'z self) {
16         let _ = &mut self.x; //~ ERROR cannot borrow
17     }
18 
foo1(&self, other: &Z)19     fn foo1(&self, other: &Z) {
20         let _ = &mut self.x; //~ ERROR cannot borrow
21         let _ = &mut other.x; //~ ERROR cannot borrow
22     }
23 
foo2<'a>(&'a self, other: &Z)24     fn foo2<'a>(&'a self, other: &Z) {
25         let _ = &mut self.x; //~ ERROR cannot borrow
26         let _ = &mut other.x; //~ ERROR cannot borrow
27     }
28 
foo3<'a>(self: &'a Self, other: &Z)29     fn foo3<'a>(self: &'a Self, other: &Z) {
30         let _ = &mut self.x; //~ ERROR cannot borrow
31         let _ = &mut other.x; //~ ERROR cannot borrow
32     }
33 
foo4(other: &Z)34     fn foo4(other: &Z) {
35         let _ = &mut other.x; //~ ERROR cannot borrow
36     }
37 
38 }
39 
with_arg(z: Z, w: &Z)40 pub fn with_arg(z: Z, w: &Z) {
41     let _ = &mut z.x; //~ ERROR cannot borrow
42     let _ = &mut w.x; //~ ERROR cannot borrow
43 }
44 
with_tuple()45 pub fn with_tuple() {
46     let mut y = 0;
47     let x = (&y,);
48     *x.0 = 1;
49     //~^ ERROR cannot assign to `*x.0`, which is behind a `&` reference
50 }
51