3 ms·
No you can't, there is a specific error for that. You can try it: struct Foo; impl Copy for Foo {} impl Drop for Foo { fn drop(&mut se
by est31 4y ago
No you can't, there is a specific error for that. You can try it:
struct Foo;
impl Copy for Foo {}
impl Drop for Foo {
fn drop(&mut self) {
// ...
}
}
It gives the error:
error[E0184]: the trait `Copy` may not be implemented for this type; the type has a destructor
--> src/main.rs:3:1
|
3 | impl Copy for Foo {}
| ^^^^^^^^^^^^^^^^^^^^ `Copy` not allowed on types with destructors
See also the "When can't my type be Copy?" section of the Rust documentation: https://doc.rust-lang.org/1.62.0/std/marker/trait.Copy.html#when-cant-my-type-be-copy https://doc.rust-lang.org/1.62.0/std/marker/trait.Copy.html#...