The address of a value is compared with nil, which it never is
What it finds
if &cfg != nil: taking the address of a variable or a composite literal always gives a pointer that is not nil, so the comparison has a fixed result. The check was usually meant for the variable itself, or for a pointer it holds.
Reported are comparisons with == or != between the predeclared nil and an expression of the form &x.
From the rule's source, address_compared_with_nil.rs.
package p type config struct{ name string } func f(c config, p *config) bool { if &c != nil {tx0 reports: &c is never nil, so this comparison is always true return true } if nil == (&config{}) {tx0 reports: &config{} is never nil, so this comparison is always false return false } return p != nil} 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:
[rules]
"tx0/go:address-compared-with-nil" = "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/go:address-compared-with-nil] reason="..."tx0 explain tx0/go:address-compared-with-nil shows the same in the terminal. Found a false positive? Report it.