A local variable has the name of a variable or parameter of an enclosing scope in the same function
What it finds
int i; ... for (...) { int i; ... }: the inner variable hides the outer one, and code in the inner block that was meant to use the outer one silently uses the new one.
From the rule's source, shadowed_variable.rs.
int f(int n){ int i = 0; int total = 0; for (int k = 0; k < n; k++) { int i = k;tx0 reports: i hides a variable of the same name declared around it int n = i;tx0 reports: n hides a variable of the same name declared around it total += n; } return total + i;} 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:
[rules]
"tx0/c:shadowed-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:shadowed-variable] reason="..."tx0 explain tx0/c:shadowed-variable shows the same in the terminal. Found a false positive? Report it.