Both operands of a binary operator are the same expression

tx0/csharp:identical-operandsdefaultwarningreliability/logicdepth fastbug

What it finds

a == a, x - x, done && done and count / count have a result that does not depend on the operand, or no effect at all: one side was meant to be something else. Operands with calls, increments or assignments are left alone, since they may differ between the two evaluations, and so are == and != on operands that may be floating point, where they test for NaN.

From the rule's source, identical_operands.rs.

Example from the rule's tests
class Check{    bool Run(int a, int b, bool done, double d)    {        var x = a - a;tx0 reports: both operands of - are a        if (done && done)tx0 reports: both operands of && are done        {            return a == a;tx0 reports: both operands of == are a        }        var nan = d != d;        return a == b || Next() == Next();    }     int Next() => 1;}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:identical-operands" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/csharp:identical-operands] reason="..."

tx0 explain tx0/csharp:identical-operands shows the same in the terminal. Found a false positive? Report it.