A value is assigned to itself
What it finds
p->len = p->len;, a[i] = a[i];: assigning something to itself does nothing, and usually stands for an assignment to something else, as p->len = len.
A plain variable assigned to itself, x = x;, is left alone: it is a common way to silence a compiler's warning about an unused parameter or a variable that may be used before it is set.
Every name in the target must be declared in the file, so that no macro hides a call or a different object behind it. Writing a volatile object back to itself can be the point, as with a hardware register, so the type of the target must show that it is not volatile. Targets that call something, which may be a macro, are left alone, and so is everything given to a macro.
From the rule's source, self_assignment.rs.
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/cpp:self-assignment" = "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/cpp:self-assignment] reason="..."tx0 explain tx0/cpp:self-assignment shows the same in the terminal. Found a false positive? Report it.