A declaration reuses the name of a predeclared function or type such as len, copy or string

tx0/go:shadowed-builtinstrictwarningmaintainability

What it finds

len := 3 or func f(copy []byte): within its scope the new name hides the builtin, so a later len(s) fails to compile or, worse for new, close or a type such as error, means something else to the next reader.

Variables, constants, parameters, results and functions declared in the file are reported when their name is a predeclared function (append, cap, clear, close, complex, copy, delete, imag, len, make, max, min, new, panic, print, println, real, recover) or type (any, bool, byte, error, rune, string and the numeric types). Fields and methods do not hide anything and are not checked.

From the rule's source, shadowed_builtin.rs.

Example from the rule's tests
package p func f(s []int, copy []int) int {tx0 reports: copy hides the predeclared copy	len := 3tx0 reports: len hides the predeclared len	n := len	n, len = n+1, 4	return n + cap(s)} type box struct{ len int } func (b box) size() int { return b.len }
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 from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

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

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