2015-01-07 20:53:58 -06:00
|
|
|
#![feature(box_syntax)]
|
|
|
|
|
2014-03-06 11:55:35 -06:00
|
|
|
struct Foo {
|
2015-01-08 04:54:35 -06:00
|
|
|
x: isize
|
2014-03-06 11:55:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for Foo {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
println!("drop {}", self.x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-02-17 14:41:32 -06:00
|
|
|
let mut ptr: Box<_> = box Foo { x: 0 };
|
2015-02-01 11:44:15 -06:00
|
|
|
let mut test = |foo: &Foo| {
|
2014-03-06 11:55:35 -06:00
|
|
|
println!("access {}", foo.x);
|
2014-05-05 20:56:44 -05:00
|
|
|
ptr = box Foo { x: ptr.x + 1 };
|
2014-03-06 11:55:35 -06:00
|
|
|
println!("access {}", foo.x);
|
|
|
|
};
|
2014-07-07 18:35:15 -05:00
|
|
|
test(&*ptr);
|
2014-03-06 11:55:35 -06:00
|
|
|
//~^ ERROR: cannot borrow `*ptr` as immutable
|
|
|
|
}
|