]> git.lizzy.rs Git - rust.git/commit
shallow Clone for #[derive(Copy,Clone)]
authorAlex Burka <aburka@seas.upenn.edu>
Thu, 4 Feb 2016 00:40:59 +0000 (19:40 -0500)
committerAlex Burka <aburka@seas.upenn.edu>
Tue, 26 Apr 2016 17:49:29 +0000 (13:49 -0400)
commit9249e6a1e2ef57bb6e329e6477beed31647236b1
tree7c95b5476a6fa184d8fac7afaf11084762a1e719
parent42ea682fc495b6ec362db0aafba69e56c7aa0a9c
shallow Clone for #[derive(Copy,Clone)]

Changes #[derive(Copy, Clone)] to use a faster impl of Clone when
both derives are present, and there are no generics in the type.

The faster impl is simply returning *self (which works because the
type is also Copy). See the comments in libsyntax_ext/deriving/clone.rs
for more details.

There are a few types which are Copy but not Clone, in violation
of the definition of Copy. These include large arrays and tuples. The
very existence of these types is arguably a bug, but in order for this
optimization not to change the applicability of #[derive(Copy, Clone)],
the faster Clone impl also injects calls to a new function,
core::clone::assert_receiver_is_clone, to verify that all members are
actually Clone.

This is not a breaking change, because pursuant to RFC 1521, any type
that implements Copy should not do any observable work in its Clone
impl.
src/libcore/clone.rs
src/libsyntax_ext/deriving/clone.rs
src/libsyntax_ext/deriving/decodable.rs
src/libsyntax_ext/deriving/encodable.rs
src/libsyntax_ext/deriving/generic/mod.rs
src/test/compile-fail/deriving-copyclone.rs [new file with mode: 0644]
src/test/run-pass/copy-out-of-array-1.rs
src/test/run-pass/deriving-copyclone.rs [new file with mode: 0644]
src/test/run-pass/hrtb-opt-in-copy.rs
src/test/run-pass/issue-13264.rs
src/test/run-pass/issue-3121.rs