Open
Description
Of these 4 ways to derive Copy and Clone:
#[derive(Copy, Clone)]
struct Foo(i32);
#[derive(Clone, Copy)]
struct Bar(i32);
#[derive(Copy)]
#[derive(Clone)]
struct Baz(i32);
#[derive(Clone)]
#[derive(Copy)]
struct Qux(i32);
The last one (derive Clone, then derive Copy) does not use the simplified form of the Clone derive for Copy types:
struct Foo(i32);
#[automatically_derived]
impl ::core::marker::Copy for Foo { }
#[automatically_derived]
impl ::core::clone::Clone for Foo {
#[inline]
fn clone(&self) -> Foo {
let _: ::core::clone::AssertParamIsClone<i32>;
*self
}
}
struct Bar(i32);
#[automatically_derived]
impl ::core::clone::Clone for Bar {
#[inline]
fn clone(&self) -> Bar {
let _: ::core::clone::AssertParamIsClone<i32>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for Bar { }
struct Baz(i32);
#[automatically_derived]
impl ::core::clone::Clone for Baz {
#[inline]
fn clone(&self) -> Baz {
let _: ::core::clone::AssertParamIsClone<i32>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for Baz { }
struct Qux(i32);
#[automatically_derived]
impl ::core::marker::Copy for Qux { }
#[automatically_derived]
impl ::core::clone::Clone for Qux {
#[inline]
fn clone(&self) -> Qux { Qux(::core::clone::Clone::clone(&self.0)) }
}
I don't think this leads to any problems currently, but it's an odd (kind of amusing) inconsistency and may (citation needed) make for slightly worse codegen.