Closed
Description
So I was curious how Drop handles cycles, because this could lead to dangling pointers, which is why __del__
might not be called in Python. And indeed the below example does not call Drop.
But t
is moved into u
, so why does this compile at all?
struct Test {
a: int,
b: Option<Box<Test>>,
}
impl Drop for Test {
fn drop(&mut self) {
println!("Dropping {}", self.a);
}
}
fn stuff() {
let mut t = Test { a: 1, b: None};
let mut u = Test { a: 2, b: Some(box t)};
t.b = Some(box u);
println!("done");
}
fn main() {
stuff();
println!("Hello, world!")
}