]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/borrowck-nested-calls.rs
auto merge of #11299 : brson/rust/exp10, r=pcwalton
[rust.git] / src / test / run-pass / borrowck-nested-calls.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 // xfail-test #5074 nested method calls
12
13 // Test that (safe) nested calls with `&mut` receivers are permitted.
14
15 struct Foo {a: uint, b: uint}
16
17 impl Foo {
18     pub fn inc_a(&mut self, v: uint) { self.a += v; }
19
20     pub fn next_b(&mut self) -> uint {
21         let b = self.b;
22         self.b += 1;
23         b
24     }
25 }
26
27 pub fn main() {
28     let mut f = Foo {a: 22, b: 23};
29     f.inc_a(f.next_b());
30     assert_eq!(f.a, 22+23);
31     assert_eq!(f.b, 24);
32 }