# no-self-assignment

Disallow assigning a stable place to itself

Assigning a stable storage place to itself leaves its value unchanged and performs a useless write.
Instead, you SHOULD remove the assignment or correct the unintended operand.

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

## Reported

```ds title="main.ds"
function retain(value: int32): int32 {
    let result = value;
    result = result;
    return result;
}
```

## Accepted

```ds title="main.ds"
function retain(value: int32): int32 {
    const result = value;
    return result;
}
```

## Prior art

- [Clippy · self_assignment](https://rust-lang.github.io/rust-clippy/master/index.html#self_assignment)
- [ESLint · no-self-assign](https://eslint.org/docs/latest/rules/no-self-assign)

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