# redundant-clone

Disallow clones proven unnecessary by ownership and liveness

Cloning an owned value at its final use duplicates the value before the original is discarded.
Instead, you SHOULD move the original value when it is not used afterward.

- Category: performance
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
import { rc } from "destack:memory";

function retain(value: rc.Rc<int32>): rc.Rc<int32> {
    return value.clone();
}
```

## Accepted

```ds title="main.ds"
import { rc } from "destack:memory";

function retain(value: rc.Rc<int32>): rc.Rc<int32> {
    return value;
}
```

## Prior art

- [Clippy · redundant_clone](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone)

[language/linter/src/rules/performance/redundant_clone.rs:7](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/performance/redundant_clone.rs#L7)
