An if tests the constant true or false, so one of its branches never runs

tx0/go:constant-conditionrecommendedwarningbug

What it finds

if false { ... } or if true { ... } else { ... }: the condition never changes, so one branch is dead code. Usually it was switched off while debugging and left behind, and code that should run, or should not, is affected.

The condition must be the predeclared true or false, possibly negated or in parentheses. A named constant is not reported, since toggling behavior with a constant is a deliberate way to compile code in or out.

From the rule's source, constant_condition.rs.

Example from the rule's tests
package p const debug = false func f(x int) int {	if false {tx0 reports: this condition is always false, so the branch never runs		x++	}	if !false {tx0 reports: this condition is always true, so the else never runs		x--	}	if debug {		x *= 2	}	return 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 from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:constant-condition" = "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/go:constant-condition] reason="..."

tx0 explain tx0/go:constant-condition shows the same in the terminal. Found a false positive? Report it.