1 struct Point { x: isize, y: isize }
4 let mut p
= Point {x: 3, y: 4}
;
7 // This assignment is illegal because the field x is not
8 // inherently mutable; since `p` was made immutable, `p.x` is now
9 // immutable. Otherwise the type of &_q.x (&isize) would be wrong.
10 p
.x
= 5; //~ ERROR cannot assign to `p.x` because it is borrowed
15 // this is sort of the opposite. We take a loan to the interior of `p`
16 // and then try to overwrite `p` as a whole.
18 let mut p
= Point {x: 3, y: 4}
;
20 p
= Point {x: 5, y: 7}
;//~ ERROR cannot assign to `p` because it is borrowed
21 p
.x
; // silence warning
26 // just for completeness's sake, the easy case, where we take the
27 // address of a subcomponent and then modify that subcomponent:
29 let mut p
= Point {x: 3, y: 4}
;
31 p
.y
= 5; //~ ERROR cannot assign to `p.y` because it is borrowed