]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/borrowck-assign-to-subfield.rs
10b5825cdd6242031a0ab653709f500785db090a
[rust.git] / src / test / run-pass / borrowck-assign-to-subfield.rs
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.
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
11 pub fn main() {
12     struct A {
13         a: int,
14         w: B,
15     }
16     struct B {
17         a: int
18     }
19     let mut p = A {
20         a: 1,
21         w: B {a: 1},
22     };
23
24     // even though `x` is not declared as a mutable field,
25     // `p` as a whole is mutable, so it can be modified.
26     p.a = 2;
27
28     // this is true for an interior field too
29     p.w.a = 2;
30 }