Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Copy a subtrait of Clone #23860

Merged
merged 7 commits into from
Apr 2, 2015
Merged

Conversation

nikomatsakis
Copy link
Contributor

Logically, Copy: Clone makes sense, since Copy basically means "I can clone this with just memcpy". This also means that one can start out with a Copy bound and relax it to a Clone bound.

This is a [breaking-change] because one must change #[derive(Copy)] to #[derive(Copy,Clone)]. In some cases, deriving doesn't create a proper clone impl (notably around fixed-length arrays), in which case you should write one by hand. Because the type in question is Copy, this is very simple:

impl Clone for Foo { fn clone(&self) -> Foo { *self } }

Fixes #23790.

r? @aturon (stabilization issue)

@@ -8,10 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

<<<<<<< HEAD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can't be right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would guess not

@aturon
Copy link
Member

aturon commented Mar 30, 2015

r=me once bad merge is resolved.

@bors
Copy link
Contributor

bors commented Mar 30, 2015

☔ The latest upstream changes (presumably #23673) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis
Copy link
Contributor Author

Created a discuss thread about this PR http://internals.rust-lang.org/t/making-copy-a-subtrait-of-clone-pr-23860/1777

@theemathas
Copy link
Contributor

I have always assumed that Copy was not a subtrait of Clone because of &T.

Turns out that &T is both Copy and Clone, after all.

👍 😃

@nikomatsakis
Copy link
Contributor Author

@bors r=aturon 32b6ec6

@nikomatsakis
Copy link
Contributor Author

oh, needs merge.

@bors
Copy link
Contributor

bors commented Mar 31, 2015

☔ The latest upstream changes (presumably #23549) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis
Copy link
Contributor Author

@bors r= aturon 1b5ac16

@bors
Copy link
Contributor

bors commented Apr 1, 2015

📌 Commit 1b5ac16 has been approved by ``

@nikomatsakis
Copy link
Contributor Author

@bors r=aturon 1b5ac16

@nikomatsakis
Copy link
Contributor Author

@bors r=aturon c35c468

@Manishearth
Copy link
Member

Would this bloat crate size for crates that derive Copy on exported types but not Clone?

I'm also a bit concerned if this affects #![no_std] since Copy is a lang item.

@nikomatsakis
Copy link
Contributor Author

@bors r=aturon 943729f

@Manishearth
Copy link
Member

@nikomatsakis
Copy link
Contributor Author

@Manishearth that should be fixed by the most recent push.

@bors
Copy link
Contributor

bors commented Apr 2, 2015

☔ The latest upstream changes (presumably #23955) made this pull request unmergeable. Please resolve the merge conflicts.

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Apr 2, 2015
Conflicts:
	src/test/compile-fail/coherence-impls-copy.rs
@alexcrichton
Copy link
Member

gah I missed this in the rollup!

@bors bors merged commit 4496433 into rust-lang:master Apr 2, 2015
andersk added a commit to andersk/image-rs that referenced this pull request Apr 3, 2015
As per rust-lang/rust#23860, Copy now extends
Clone.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
andersk added a commit to andersk/image-rs that referenced this pull request Apr 3, 2015
As per rust-lang/rust#23860, Copy now extends
Clone.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
DaGenix added a commit to DaGenix/rust-crypto that referenced this pull request Apr 4, 2015
jooert added a commit to jooert/rust-bswap that referenced this pull request Apr 29, 2015
Swap order of input and output parameters of ptr::copy_nonoverlapping
(rust-lang/rust#23866), remove usage of
std::num::Int (rust-lang/rust#23549), change
(rust-lang/rust#23860).
jooert added a commit to jooert/rust-bswap that referenced this pull request Apr 29, 2015
Swap order of input and output parameters of ptr::copy_nonoverlapping
(rust-lang/rust#23866), remove usage of
std::num::Int (rust-lang/rust#23549), change
(rust-lang/rust#23860).
@nikomatsakis nikomatsakis deleted the copy-requires-clone branch March 30, 2016 16:12
BlockBlazeDev added a commit to BlockBlazeDev/rust-crypto that referenced this pull request Aug 8, 2024
BlockBlazeDev added a commit to BlockBlazeDev/rust-crypto that referenced this pull request Aug 8, 2024
BlockBlazeDev added a commit to BlockBlazeDev/rust-crypto that referenced this pull request Aug 8, 2024
cosmycoder added a commit to cosmycoder/rust-crypto that referenced this pull request Sep 5, 2024
cosmycoder added a commit to cosmycoder/rust-crypto that referenced this pull request Sep 5, 2024
cosmycoder added a commit to cosmycoder/rust-crypto that referenced this pull request Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make Copy: Clone
7 participants