# PSA: Copy is becoming opt-in

**URL:** <https://internals.rust-lang.org/t/psa-copy-is-becoming-opt-in/982>\
**Category:** community\
**Created:** [December 5, 2014, 5:00pm UTC](https://internals.rust-lang.org/t/psa-copy-is-becoming-opt-in/982 "2014-12-05T17:00:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikomatsakis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nikomatsakis/32/5410_2.png) [@nikomatsakis](https://internals.rust-lang.org/u/nikomatsakis)\
**Post date:** [December 5, 2014, 5:00pm UTC](https://internals.rust-lang.org/t/psa-copy-is-becoming-opt-in/982/1 "2014-12-05T17:00:50Z")

</div>

There is a long-approved but also long-delayed breaking change [coming down the pipeline](https://github.com/rust-lang/rust/pull/19566). The idea is that struct/enum types will no longer be implicitly copyable, even if they contain POD data. They will move from place to place just like a `Box` etc.

For types that _should_ be implicitly copyable, you can manually implement `Copy`. This can be done most easily by writing `#[deriving(Copy)]` (or, more likely, throwing `Copy` into a `#[deriving]` you already have).

There is also a lint that warns you if you have a type that _could_ be copy but is not. The intention is to help you ensure that you do not forget to derive `Copy` when it is necessary. The idea is that if you have a type that _is_ copyable but you don’t want to guarantee that for API compatibility, you can annotate it with a `#[allow()]`.

This is part of the [opt-in-builtin-types RFC](https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).

**UPDATE:** See [this note](http://discuss.rust-lang.org/t/psa-copy-is-becoming-opt-in/982/4?u=nikomatsakis) about a temporary feature-gate that may aid you in transitioning.

---

<div class="post-metadata">

**Author:** ![bstrie](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bstrie/32/94_2.png) [@bstrie](https://internals.rust-lang.org/u/bstrie)\
**Post date:** [December 6, 2014, 4:35pm UTC](https://internals.rust-lang.org/t/psa-copy-is-becoming-opt-in/982/2 "2014-12-06T16:35:13Z")

</div>

Does #deriving(Copy) derive Clone as well? The issue for this ([https://github.com/rust-lang/rust/issues/17884](https://github.com/rust-lang/rust/issues/17884)) was last updated before multidispatch arrived.

---

<div class="post-metadata">

**Author:** ![nikomatsakis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nikomatsakis/32/5410_2.png) [@nikomatsakis](https://internals.rust-lang.org/u/nikomatsakis)\
**Post date:** [December 8, 2014, 6:49pm UTC](https://internals.rust-lang.org/t/psa-copy-is-becoming-opt-in/982/3 "2014-12-08T18:49:10Z")

</div>

`#[deriving(Copy)]` does not currently derive `Clone` as well. I would like to see `#[deriving]` take care of things like this (also `PartialOrd` vs `Ord`) but the issue is somewhat separate.

---

<div class="post-metadata">

**Author:** ![nikomatsakis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nikomatsakis/32/5410_2.png) [@nikomatsakis](https://internals.rust-lang.org/u/nikomatsakis)\
**Post date:** [December 8, 2014, 6:49pm UTC](https://internals.rust-lang.org/t/psa-copy-is-becoming-opt-in/982/4 "2014-12-08T18:49:55Z")

</div>

For convenience, I have also added a feature-gate `opt_out_copy` that lets you revert back to the old behavior. This can be used to keep older crates compiling while you transition them. Note though that this opt-out-copy behavior will eventually be removed.

---

<div class="post-metadata">

**Author:** ![petrochenkov](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/petrochenkov/32/2784_2.png) [@petrochenkov](https://internals.rust-lang.org/u/petrochenkov)\
**Post date:** [December 9, 2014, 8:15am UTC](https://internals.rust-lang.org/t/psa-copy-is-becoming-opt-in/982/5 "2014-12-09T08:15:59Z")

</div>

> [@nikomatsakis](#):
>
> There is also a lint that warns you if you have a type that could be copy but is not.

Does the lint work for all type definitions or only for `pub`lic ones?

---

<div class="post-metadata">

**Author:** ![nikomatsakis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nikomatsakis/32/5410_2.png) [@nikomatsakis](https://internals.rust-lang.org/u/nikomatsakis)\
**Post date:** [March 25, 2019, 8:23am UTC](https://internals.rust-lang.org/t/psa-copy-is-becoming-opt-in/982/6 "2019-03-25T08:23:19Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
