# inconsistent-equality-implementation

Disallow mixing derived and written equality or hashing implementations

Writing equality while deriving hashing, or writing hashing while deriving equality, can assign different hashes to equal values.
Instead, you MUST derive both protocols or implement both protocols from the same fields.

- Category: correctness
- Level: error
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
@derive(Hash)
struct Key {
    value: int32;
}

extension of Key implements Equal<Key> {
    equal(&readonly this, other: &readonly Key): boolean {
        return this.value % 10 == other.value % 10;
    }
}
```

## Accepted

```ds title="main.ds"
@derive(Equal, Hash)
struct Key {
    value: int32;
}
```

## Prior art

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

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