Closed
Description
While the destructor for newtypes always seems to run the same is not true for regular or unit-like structs.
struct Foo;
struct Bar { x: int }
struct Baz(int);
impl Drop for Foo {
fn drop(&mut self) {
println!("finalize Foo");
}
}
impl Drop for Bar {
fn drop(&mut self) {
println!("finalize Bar");
}
}
impl Drop for Baz {
fn drop(&mut self) {
println!("finalize Baz");
}
}
fn main() {
{ let _x = Foo; }
{ let _x = Bar { x: 21 }; }
{ let _x = Baz(21); }
println!("------------");
{ let _ = Foo; }
{ let _ = Bar { x: 21 }; }
{ let _ = Baz(21); }
}
-> % rust run test.rs
finalize Foo
finalize Bar
finalize Baz
------------
finalize Baz
I'm not sure which is the right behaviour.