When a type that is also Copy has #[derive(Clone)], the derived implementation should be:
fn clone(&self) -> Self { *self }
From #27750 (comment)
As the example in #27750 (comment) shows, even when a composite type like Composite is Copy, its clone implementation may be less efficient than its Copy impl, due to copying fields individually instead of as a block.
Maybe being Copy is hard to determine exactly by the time #[derive(Clone)] needs to do its thing, but at least this could happen when both traits are in the same derive attribute? #[derive(Copy, Clone)]
When a type that is also
Copyhas#[derive(Clone)], the derived implementation should be:From #27750 (comment)
Maybe being
Copyis hard to determine exactly by the time#[derive(Clone)]needs to do its thing, but at least this could happen when both traits are in the same derive attribute?#[derive(Copy, Clone)]