# About warning: using \`clone\` on a \`Copy\` type \[clone\_on\_copy\]

**URL:** <https://discourse.pijul.org/t/about-warning-using-clone-on-a-copy-type-clone-on-copy/65>\
**Category:** Development\
**Created:** [August 12, 2017, 1:51pm UTC](https://discourse.pijul.org/t/about-warning-using-clone-on-a-copy-type-clone-on-copy/65 "2017-08-12T13:51:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabomgp](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/gabomgp/32/57_2.png) [@gabomgp](https://discourse.pijul.org/u/gabomgp)\
**Post date:** [August 12, 2017, 1:51pm UTC](https://discourse.pijul.org/t/about-warning-using-clone-on-a-copy-type-clone-on-copy/65/1 "2017-08-12T13:51:08Z")

</div>

I’m fixing the warnings from clippy in pijul’s source code and i have a question:

In many places the types _LineId_, _PatchId_ and _Inode_ are explicitly cloned. These types are Copy types, and calling explicitly clone on it is unnecessary. They are copied by memcopy. But, i don’t know if is preferable for pijul, maybe by readibility reasons, or these types might not be more ‘copy’ types in the future.

Anyway, the question is: should I remove unnecessary calls to Clone for these types?

---

<div class="post-metadata">

**Author:** ![pmeunier](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/pmeunier/32/4_2.png) [@pmeunier](https://discourse.pijul.org/u/pmeunier)\
**Post date:** [August 12, 2017, 2:08pm UTC](https://discourse.pijul.org/t/about-warning-using-clone-on-a-copy-type-clone-on-copy/65/2 "2017-08-12T14:08:52Z")

</div>

They were designed explicitly to be small types (possibly smaller than 64 bits), so you’re right, this _is_ a design choice, and you can safely remove the clones.

I believe they come from the first version of Pijul, written in a language not low-level enough to provide guarantees on memory representation like "`struct A([u8; 11], [u8; 31])` and `struct B([u8; 42])` have the same representation".

(That language didn’t have `[u8; N]` to begin with).

---

<div class="post-metadata">

**Author:** ![laumann](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/laumann/32/8_2.png) [@laumann](https://discourse.pijul.org/u/laumann)\
**Post date:** [August 14, 2017, 1:13pm UTC](https://discourse.pijul.org/t/about-warning-using-clone-on-a-copy-type-clone-on-copy/65/3 "2017-08-14T13:13:41Z")

</div>

I was considering running clippy on Pijul as well, glad you’re doing it @gabomgp!

I have some related questions about code style:

- There are a bunch of `try!` statements and that could directly be replaced by `?`.
- There are quite a few unnecessary `return` statements
- In many cases an `Ok(())` is returned at the bottom, where the `Result` of the previous statement could just as well be returned.

@pmeunier Would you accept patches that just “cleaned” these things up?

---

<div class="post-metadata">

**Author:** ![pmeunier](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/pmeunier/32/4_2.png) [@pmeunier](https://discourse.pijul.org/u/pmeunier)\
**Post date:** [August 14, 2017, 1:30pm UTC](https://discourse.pijul.org/t/about-warning-using-clone-on-a-copy-type-clone-on-copy/65/4 "2017-08-14T13:30:10Z")

</div>

> [@laumann](#):
>
> @pmeunier Would you accept patches that just “cleaned” these things up?

I would! These are usually unpleasant patches, because they are likely to cause conflicts. But go ahead! They are badly needed.

---

<div class="post-metadata">

**Author:** ![laumann](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/laumann/32/8_2.png) [@laumann](https://discourse.pijul.org/u/laumann)\
**Post date:** [August 14, 2017, 2:15pm UTC](https://discourse.pijul.org/t/about-warning-using-clone-on-a-copy-type-clone-on-copy/65/5 "2017-08-14T14:15:36Z")

</div>

@pmeunier Thanks, will do!

@gabomgp I ran clippy myself and [here’s the report](http://sprunge.us/XUfa). Some of the suggestions are quite interesting, like:

```auto
warning: this pattern creates a reference to a reference
  --> src/commands/keys.rs:92:17
   |
92 | if let Some(ref user_host) = args.server {warning: this pattern creates a reference to a reference
  --> src/commands/keys.rs:92:17
   |
92 | if let Some(ref user_host) = args.server {
   | ^^^^^^^^^^^^^
   |

   | ^^^^^^^^^^^^^
   |
   = = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_borrow

```
