2014-03-06 17:55:35 +00:00
|
|
|
struct Foo {
|
2015-01-08 10:54:35 +00:00
|
|
|
x: isize
|
2014-03-06 17:55:35 +00:00
|
|
|
}
|
|
|
|
|
2022-07-07 02:36:10 +00:00
|
|
|
|
2014-03-06 17:55:35 +00:00
|
|
|
impl Drop for Foo {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
println!("drop {}", self.x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-07 02:36:10 +00:00
|
|
|
|
2014-03-06 17:55:35 +00:00
|
|
|
fn main() {
|
2022-07-07 02:36:10 +00:00
|
|
|
let mut ptr: Box<_> = Box::new(Foo { x: 0 });
|
2015-02-01 17:44:15 +00:00
|
|
|
let mut test = |foo: &Foo| {
|
2014-03-06 17:55:35 +00:00
|
|
|
println!("access {}", foo.x);
|
2022-07-07 02:36:10 +00:00
|
|
|
ptr = Box::new(Foo { x: ptr.x + 1 });
|
2014-03-06 17:55:35 +00:00
|
|
|
println!("access {}", foo.x);
|
|
|
|
};
|
2014-07-07 23:35:15 +00:00
|
|
|
test(&*ptr);
|
2014-03-06 17:55:35 +00:00
|
|
|
//~^ ERROR: cannot borrow `*ptr` as immutable
|
|
|
|
}
|