An expression statement computes a value and throws it away

tx0/c:expression-without-effectdefaultwarningbug

What it finds

x == 0; or count + 1;: the statement computes a value and does nothing with it, so it has no effect. A comparison often stands where an assignment was meant.

The expression must be a comparison, arithmetic or a negation without calls, assignments or increments, whose names all refer to declarations in the file; a dereference alone, which may read a device register, and the value at the end of a statement expression are left alone, and so is a statement that is not in a block, and every statement of a file with syntax errors.

From the rule's source, expression_without_effect.rs.

Example from the rule's tests
int f(void); void stmts(int x, volatile int *reg){  x == 0;tx0 reports: the value of this expression is not used  x + 1;tx0 reports: the value of this expression is not used  *reg;  f() == 0;  x = 1;  (void)x;}
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/c:expression-without-effect" = "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/c:expression-without-effect] reason="..."

tx0 explain tx0/c:expression-without-effect shows the same in the terminal. Found a false positive? Report it.