]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/borrowck-loan-rcvr.rs
Convert most code to new inner attribute syntax.
[rust.git] / src / test / compile-fail / borrowck-loan-rcvr.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 #![feature(managed_boxes)]
12
13 struct point { x: int, y: int }
14
15 trait methods {
16     fn impurem(&self);
17     fn blockm(&self, f: ||);
18 }
19
20 impl methods for point {
21     fn impurem(&self) {
22     }
23
24     fn blockm(&self, f: ||) { f() }
25 }
26
27 fn a() {
28     let mut p = point {x: 3, y: 4};
29
30     // Here: it's ok to call even though receiver is mutable, because we
31     // can loan it out.
32     p.impurem();
33
34     // But in this case we do not honor the loan:
35     p.blockm(|| { //~ ERROR cannot borrow `p` as mutable
36         p.x = 10;
37     })
38 }
39
40 fn b() {
41     let mut p = point {x: 3, y: 4};
42
43     // Here I create an outstanding loan and check that we get conflicts:
44
45     let l = &mut p;
46     p.impurem(); //~ ERROR cannot borrow
47
48     l.x += 1;
49 }
50
51 fn main() {
52 }