-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)A-trait-systemArea: Trait systemArea: Trait systemA-type-systemArea: Type systemArea: Type systemP-mediumMedium priorityMedium priority
Milestone
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.
Metadata
Metadata
Assignees
Labels
A-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)A-trait-systemArea: Trait systemArea: Trait systemA-type-systemArea: Type systemArea: Type systemP-mediumMedium priorityMedium priority