A local variable is declared but never used

tx0/c:unused-local-variablestrictwarningsmell

What it finds

int unused;: a variable the function never mentions again is noise, and often a sign that code meant to use it uses another variable.

The name must occur nowhere else in the function, also not in macros or in branches of conditional directives that are not read, and the declaration must not be marked as possibly unused or bound to a register.

From the rule's source, unused_local_variable.rs.

Example from the rule's tests
int f(int a){  int spare;tx0 reports: spare is never used  int used = a;  int maybe = 0;#if 0  maybe = 1;#endif  return used;}
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 from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/c:unused-local-variable" = "warning"

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:unused-local-variable] reason="..."

tx0 explain tx0/c:unused-local-variable shows the same in the terminal. Found a false positive? Report it.