What's bad if auto impl `clone` for ZST

question arised from this quiz

pointer to a ZST(zero size types) is default impl clone, a ZST is not.

A ZST may be or may be not implemented with Clone.

impl Clone for () does exist.

But A isn't implemented with Clone unless you implement it yourself, like #[derive(Clone)] struct A;.

The explanation from the quiz is clear, and I think it's more about how Rust finds a method which is stated in the Reference.

1 Like

Right now it's possible to use a ZST instance for its uniqueness.

For example, you could have a library that gives out a ZST for "has been initialized", and the uninitialization call for the library would consume that ZST, so the library can thus trust that it's not going to be uninitialized multiple times having only been initialized once.

That would no longer work if every ZST was always clonable.

(Also, in general, it's best for ZSTs to work like everything else. Special-casing them is net extra confusion overall.)

7 Likes