# suspicious-operator-implementation

Disallow direct operator implementations built on a different operator

Directly combining an operator receiver and operand with a different operator commonly indicates a copied or mistyped body.
Instead, you SHOULD use the operator implemented by the enclosing protocol.

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

## Reported

```ds title="main.ds"
struct Score {
    value: int32;
}

extension of Score implements Add<Score> {
    type Output = Score;

    add(&readonly this, other: Score): Score {
        return Score { value: this.value - other.value };
    }
}
```

## Accepted

```ds title="main.ds"
struct Score {
    value: int32;
}

extension of Score implements Add<Score> {
    type Output = Score;

    add(&readonly this, other: Score): Score {
        return Score { value: this.value + other.value };
    }
}
```

## Prior art

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

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