Closed
Description
This code compiles and runs but seems to allow a use-after-free:
struct Foo {
x: int
}
impl Drop for Foo {
fn drop(&mut self) {
println!("drop {}", self.x);
}
}
fn main() {
let mut ptr = ~Foo { x: 0 };
let test = |foo: &Foo| {
println!("access {}", foo.x);
ptr = ~Foo { x: ptr.x + 1 };
println!("access {}", foo.x);
};
test(ptr);
}
The output is:
access 0
drop 0
access 0
drop 1
This is with rustc 0.8. It may be related to #9853 but I'm not sure.