Compiler generated copies in drop docs

From the docs on Drop:

You cannot implement both Copy and Drop on the same type. Types that are Copy get implicitly duplicated by the compiler, making it very hard to predict when, and how often destructors will be executed. As such, these types cannot have destructors.

Now I understand as a user the distinction between Copy and Clone. Copy types will get copied when explicitly assigned rather than moved. Is that all that's being referred to here by "implicitly duplicated by the compiler"? Or are there some surprising/interesting reasons the compiler is inserting other copies?

A more general take would be "the compiler is free to emit or elide copies as it sees fit", which probably wouldn't be the case if destructors were allowed.

For instance, LLVM has some memcpy-eliminating optimizations, but sometimes these regress or are otherwise not 100% reliable. Examples:

1 Like