E0416: Duplicate destructor
| Code | Category | Stability |
|---|---|---|
E0416 | Struct and enum | Permanent |
Explanation
More than one user-defined destructor is declared for the same struct type. Rue permits at most one destructor because dropping a value has one canonical user cleanup action.
Likely cause
A drop fn declaration was duplicated, or cleanup for one type was split across multiple destructor declarations. Combine the cleanup into a single destructor for that struct.
Examples
Two destructors for one struct
struct Resource { value: i32 }
drop fn Resource(self) {}
drop fn Resource(self) {}
fn main() -> i32 { 0 }
Keep one destructor per struct
struct Resource { value: i32 }
drop fn Resource(self) {}
fn main() -> i32 { 0 }