2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-12-12 01:17:54 -06:00
|
|
|
#[feature(managed_boxes)];
|
|
|
|
|
2013-02-21 17:19:40 -06:00
|
|
|
struct point { x: int, y: int }
|
2012-06-01 17:46:32 -05:00
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
trait methods {
|
2013-03-12 21:32:14 -05:00
|
|
|
fn impurem(&self);
|
2013-11-19 18:34:19 -06:00
|
|
|
fn blockm(&self, f: ||);
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl methods for point {
|
2013-03-12 21:32:14 -05:00
|
|
|
fn impurem(&self) {
|
2012-06-01 17:46:32 -05:00
|
|
|
}
|
|
|
|
|
2013-11-19 18:34:19 -06:00
|
|
|
fn blockm(&self, f: ||) { f() }
|
2012-06-01 17:46:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn a() {
|
2013-02-21 17:19:40 -06:00
|
|
|
let mut p = point {x: 3, y: 4};
|
2012-06-01 17:46:32 -05:00
|
|
|
|
2012-06-01 23:54:38 -05:00
|
|
|
// Here: it's ok to call even though receiver is mutable, because we
|
|
|
|
// can loan it out.
|
2012-06-01 17:46:32 -05:00
|
|
|
p.impurem();
|
2012-06-01 23:54:38 -05:00
|
|
|
|
|
|
|
// But in this case we do not honor the loan:
|
2013-11-21 19:23:21 -06:00
|
|
|
p.blockm(|| {
|
2013-03-15 14:24:24 -05:00
|
|
|
p.x = 10; //~ ERROR cannot assign
|
2013-11-21 19:23:21 -06:00
|
|
|
})
|
2012-06-01 17:46:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn b() {
|
2013-02-21 17:19:40 -06:00
|
|
|
let mut p = point {x: 3, y: 4};
|
2012-06-01 17:46:32 -05:00
|
|
|
|
2012-06-01 23:54:38 -05:00
|
|
|
// Here I create an outstanding loan and check that we get conflicts:
|
|
|
|
|
2013-03-15 14:24:24 -05:00
|
|
|
let l = &mut p;
|
|
|
|
p.impurem(); //~ ERROR cannot borrow
|
2012-08-17 16:09:20 -05:00
|
|
|
|
|
|
|
l.x += 1;
|
2012-06-01 17:46:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|