1 // Copyright 2012 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.
11 struct point { x: isize, y: isize }
14 let mut p = point {x: 3, y: 4};
17 // This assignment is illegal because the field x is not
18 // inherently mutable; since `p` was made immutable, `p.x` is now
19 // immutable. Otherwise the type of &_q.x (&isize) would be wrong.
20 p.x = 5; //~ ERROR cannot assign to `p.x`
25 // this is sort of the opposite. We take a loan to the interior of `p`
26 // and then try to overwrite `p` as a whole.
28 let mut p = point {x: 3, y: 4};
30 p = point {x: 5, y: 7};//~ ERROR cannot assign to `p`
31 p.x; // silence warning
36 // just for completeness's sake, the easy case, where we take the
37 // address of a subcomponent and then modify that subcomponent:
39 let mut p = point {x: 3, y: 4};
41 p.y = 5; //~ ERROR cannot assign to `p.y`