A header defines a variable with external linkage, which every file including it defines again

tx0/c:header-defines-variablestrictwarningreliability/api-misusedepth fastbug

What it finds

int retries = 3; at the top level of a header: every file that includes the header defines the variable again, and linking two of them fails with a duplicate symbol, or with -fcommon merges them silently. A header declares the variable extern and one source file defines it.

Declarations with an initializer and without static, extern or typedef count, at the top level of a file ending in .h. Some projects keep tables in headers that one source file includes, so the rule is strict.

From the rule's source, header_defines_variable.rs.

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:header-defines-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:header-defines-variable] reason="..."

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