-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[RFC] Split Copy
trait in two traits: Pod
and Copy
#23016
Conversation
r? @kmcallister (rust_highfive has picked a reviewer for you, use r? to override) |
@japaric Very nice work, thank you! I haven't looked into the details, but do you also derive |
No, the plan was to do that in the type system with a blanket impl for impl Clone for T where T: Pod {
fn clone(&self) -> T {
// NB safe! this a memcpy of Pod data (no owned/refcounted/`drop`able data here)
unsafe {
mem::transmute_copy(self)
}
}
} But! It can't be done right now because it needs negative bounds to handle some coherence problem (overlapping impls). I think it may be possible to do it in syntax extension (have |
☔ The latest upstream changes (presumably #23162) made this pull request unmergeable. Please resolve the merge conflicts. |
Closing, since we are taking the lint route. |
@japaric Thanks for pushing this along and raising the discussion! |
DO NOT MERGE NEEDS AN APPROVED RFC.
Pod
trait is used to mark types that can be cloned by simply copying its bytes on the stack.Copy
trait is used to mark types that are implictly copyable.Pod
can only be derived by structs/enums whose fields are alsoPod
Copy
can only be derived by types that arePod
, i.e.trait Copy: Pod {}
#[derive(Copy)]
syntax extension now derives both thePod
andCopy
traits.#[derive(Pod)]
syntax extension have been added to derive thePod
traitCell<T>
'sT: Copy
bound has been relaxed toT: Pod
, this lets you use it with a wider variety of types like iterators, which are not implicitly copyable.[breaking-change]s
Copy
trait, you'll have to manually implementPod
as well:impl<T> Copy for MyType<T> {} + impl<T> Pod for MyType<T> {}
#![derive(Copy)]
expand into two items, it was necessary to change the unstable#[derive]
API. This will likely break third-party#[derive]
extensions.I plon to finish writing a proper RFC by tomorrow, but here's the current draft.RFC
cc @aturon @nikomatsakis @tbu-
cc #21846