A value is assigned to itself

tx0/go:self-assignmentdefaultwarningbug

What it finds

x = x: an assignment of a variable to itself does nothing, and usually stands for an assignment to something else, such as a field of the same name.

From the rule's source, self_assignment.rs.

Example from the rule's tests
package p type S struct{ name string } func (s *S) set(name string) {	name = nametx0 reports: name is assigned to itself	s.name = s.nametx0 reports: s.name is assigned to itself	s.name = name	a, b := 1, 2	a, b = b, a	a, b = a, 3tx0 reports: a is assigned to itself	_ = _	x := []int{}	x[f()] = x[f()]	x = append(x, 1)	y := 0	y += y	_, _, _ = a, b, y} func f() int { return 0 }
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 in every tier. To turn it off for a project, set its level in tx0.toml:

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

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