Why derive(Copy, Clone) is different with derive(Clone) + impl Copy
Hi, I've encountered an unexpected but explainable case, that
#[derive(Clone)]
enum A {
A = 1,
B = 2,
C = 3,
}
impl Copy for A {}
#[derive(Clone, Copy)]
enum B {
A = 1,
B = 2,
C = 3,
}
Expanded code as
impl ::core::clone::Clone for A {
#[inline]
fn clone(self: &Self)
->
A {
match (&*self,) {
(&A::A,) => A::A,
(&A::B,) => A::B,
(&A::C,) => A::C,
}
}
}
impl ::core::clone::Clone for B {
#[inline]
fn clone(self: &Self) -> B { { *self } }
}
Note that, both A and B have Copy trait, but their derived Clone impl is quite different.
playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=90807b18bd71f650eb68ed0dec06f749 click Show HIR and hit run.