Skip to content

Commit 2580d0e

Browse files
committed
all: gofmt -w -r 'interface{} -> any' src
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent 083ef54 commit 2580d0e

File tree

445 files changed

+1906
-1875
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

445 files changed

+1906
-1875
lines changed

src/archive/tar/common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ type headerFileInfo struct {
538538
func (fi headerFileInfo) Size() int64 { return fi.h.Size }
539539
func (fi headerFileInfo) IsDir() bool { return fi.Mode().IsDir() }
540540
func (fi headerFileInfo) ModTime() time.Time { return fi.h.ModTime }
541-
func (fi headerFileInfo) Sys() interface{} { return fi.h }
541+
func (fi headerFileInfo) Sys() any { return fi.h }
542542

543543
// Name returns the base name of the file.
544544
func (fi headerFileInfo) Name() string {

src/archive/tar/reader_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ func TestFileReader(t *testing.T) {
13631363
wantLCnt int64
13641364
wantPCnt int64
13651365
}
1366-
testFnc interface{} // testRead | testWriteTo | testRemaining
1366+
testFnc any // testRead | testWriteTo | testRemaining
13671367
)
13681368

13691369
type (
@@ -1376,7 +1376,7 @@ func TestFileReader(t *testing.T) {
13761376
spd sparseDatas
13771377
size int64
13781378
}
1379-
fileMaker interface{} // makeReg | makeSparse
1379+
fileMaker any // makeReg | makeSparse
13801380
)
13811381

13821382
vectors := []struct {

src/archive/tar/tar_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
type testError struct{ error }
2525

26-
type fileOps []interface{} // []T where T is (string | int64)
26+
type fileOps []any // []T where T is (string | int64)
2727

2828
// testFile is an io.ReadWriteSeeker where the IO operations performed
2929
// on it must match the list of operations in ops.

src/archive/tar/writer_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestWriter(t *testing.T) {
6767
testClose struct { // Close() == wantErr
6868
wantErr error
6969
}
70-
testFnc interface{} // testHeader | testWrite | testReadFrom | testClose
70+
testFnc any // testHeader | testWrite | testReadFrom | testClose
7171
)
7272

7373
vectors := []struct {
@@ -1031,7 +1031,7 @@ func TestFileWriter(t *testing.T) {
10311031
wantLCnt int64
10321032
wantPCnt int64
10331033
}
1034-
testFnc interface{} // testWrite | testReadFrom | testRemaining
1034+
testFnc any // testWrite | testReadFrom | testRemaining
10351035
)
10361036

10371037
type (
@@ -1044,7 +1044,7 @@ func TestFileWriter(t *testing.T) {
10441044
sph sparseHoles
10451045
size int64
10461046
}
1047-
fileMaker interface{} // makeReg | makeSparse
1047+
fileMaker any // makeReg | makeSparse
10481048
)
10491049

10501050
vectors := []struct {

src/archive/zip/reader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ func (f *fileListEntry) Size() int64 { return 0 }
670670
func (f *fileListEntry) Mode() fs.FileMode { return fs.ModeDir | 0555 }
671671
func (f *fileListEntry) Type() fs.FileMode { return fs.ModeDir }
672672
func (f *fileListEntry) IsDir() bool { return true }
673-
func (f *fileListEntry) Sys() interface{} { return nil }
673+
func (f *fileListEntry) Sys() any { return nil }
674674

675675
func (f *fileListEntry) ModTime() time.Time {
676676
if f.file == nil {

src/archive/zip/struct.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (fi headerFileInfo) ModTime() time.Time {
163163
}
164164
func (fi headerFileInfo) Mode() fs.FileMode { return fi.fh.Mode() }
165165
func (fi headerFileInfo) Type() fs.FileMode { return fi.fh.Mode().Type() }
166-
func (fi headerFileInfo) Sys() interface{} { return fi.fh }
166+
func (fi headerFileInfo) Sys() any { return fi.fh }
167167

168168
func (fi headerFileInfo) Info() (fs.FileInfo, error) { return fi, nil }
169169

src/builtin/builtin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func close(c chan<- Type)
239239
// that point, the program is terminated with a non-zero exit code. This
240240
// termination sequence is called panicking and can be controlled by the
241241
// built-in function recover.
242-
func panic(v interface{})
242+
func panic(v any)
243243

244244
// The recover built-in function allows a program to manage behavior of a
245245
// panicking goroutine. Executing a call to recover inside a deferred
@@ -250,7 +250,7 @@ func panic(v interface{})
250250
// panicking, or if the argument supplied to panic was nil, recover returns
251251
// nil. Thus the return value from recover reports whether the goroutine is
252252
// panicking.
253-
func recover() interface{}
253+
func recover() any
254254

255255
// The print built-in function formats its arguments in an
256256
// implementation-specific way and writes the result to standard error.

src/bytes/reader_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestReaderAt(t *testing.T) {
7676
off int64
7777
n int
7878
want string
79-
wanterr interface{}
79+
wanterr any
8080
}{
8181
{0, 10, "0123456789", nil},
8282
{1, 10, "123456789", io.EOF},

src/cmd/api/goapi.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ func (w *Walker) emitMethod(m *types.Selection) {
10711071
w.emitf("method (%s%s) %s%s", w.typeString(recv), tps, m.Obj().Name(), w.signatureString(sig))
10721072
}
10731073

1074-
func (w *Walker) emitf(format string, args ...interface{}) {
1074+
func (w *Walker) emitf(format string, args ...any) {
10751075
f := strings.Join(w.scope, ", ") + ", " + fmt.Sprintf(format, args...)
10761076
if strings.Contains(f, "\n") {
10771077
panic("feature contains newlines: " + f)

src/cmd/api/testdata/src/issue21181/p/p_generic.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !amd64
12
// +build !amd64
23

34
package p

src/cmd/api/testdata/src/pkg/p1/p1.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ var m map[string]int
197197

198198
var chanVar chan int
199199

200-
var ifaceVar interface{} = 5
200+
var ifaceVar any = 5
201201

202202
var assertVar = ifaceVar.(int)
203203

src/cmd/api/testdata/src/pkg/p4/p4.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
package p4
66

7-
type Pair[T1 interface { M() }, T2 ~int] struct {
7+
type Pair[T1 interface{ M() }, T2 ~int] struct {
88
f1 T1
99
f2 T2
1010
}
1111

12-
func NewPair[T1 interface { M() }, T2 ~int](v1 T1, v2 T2) Pair[T1, T2] {
12+
func NewPair[T1 interface{ M() }, T2 ~int](v1 T1, v2 T2) Pair[T1, T2] {
1313
return Pair[T1, T2]{f1: v1, f2: v2}
1414
}
1515

src/cmd/compile/internal/importer/gcimporter_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ var importedObjectTests = []struct {
258258
{"go/internal/gcimporter.FindPkg", "func FindPkg(path string, srcDir string) (filename string, id string)"},
259259

260260
// interfaces
261-
{"context.Context", "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key interface{}) interface{}}"},
261+
{"context.Context", "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key any) any}"},
262262
{"crypto.Decrypter", "type Decrypter interface{Decrypt(rand io.Reader, msg []byte, opts DecrypterOpts) (plaintext []byte, err error); Public() PublicKey}"},
263263
{"encoding.BinaryMarshaler", "type BinaryMarshaler interface{MarshalBinary() (data []byte, err error)}"},
264264
{"io.Reader", "type Reader interface{Read(p []byte) (n int, err error)}"},

src/cmd/cover/testdata/test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func testSwitch() {
151151
}
152152

153153
func testTypeSwitch() {
154-
var x = []interface{}{1, 2.0, "hi"}
154+
var x = []any{1, 2.0, "hi"}
155155
for _, v := range x {
156156
switch func() { check(LINE, 3) }(); v.(type) {
157157
case int:
@@ -215,7 +215,7 @@ func testEmptySwitches() {
215215
switch 3 {
216216
}
217217
check(LINE, 1)
218-
switch i := (interface{})(3).(int); i {
218+
switch i := (any)(3).(int); i {
219219
}
220220
check(LINE, 1)
221221
c := make(chan int)

src/cmd/dist/buildtool.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"fmt"
1616
"os"
1717
"path/filepath"
18+
"regexp"
1819
"runtime"
1920
"strings"
2021
)
@@ -288,7 +289,11 @@ func rewriteBlock%s(b *Block) bool { panic("unused during bootstrap") }
288289
}
289290

290291
func bootstrapFixImports(srcFile string) string {
291-
lines := strings.SplitAfter(readfile(srcFile), "\n")
292+
text := readfile(srcFile)
293+
if !strings.Contains(srcFile, "/cmd/") && !strings.Contains(srcFile, `\cmd\`) {
294+
text = regexp.MustCompile(`\bany\b`).ReplaceAllString(text, "interface{}")
295+
}
296+
lines := strings.SplitAfter(text, "\n")
292297
inBlock := false
293298
for i, line := range lines {
294299
if strings.HasPrefix(line, "import (") {

src/cmd/doc/pkg.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func trim(path, prefix string) (string, bool) {
122122
// main do function, so it doesn't cause an exit. Allows testing to work
123123
// without running a subprocess. The log prefix will be added when
124124
// logged in main; it is not added here.
125-
func (pkg *Package) Fatalf(format string, args ...interface{}) {
125+
func (pkg *Package) Fatalf(format string, args ...any) {
126126
panic(PackageError(fmt.Sprintf(format, args...)))
127127
}
128128

@@ -209,7 +209,7 @@ func parsePackage(writer io.Writer, pkg *build.Package, userPath string) *Packag
209209
return p
210210
}
211211

212-
func (pkg *Package) Printf(format string, args ...interface{}) {
212+
func (pkg *Package) Printf(format string, args ...any) {
213213
fmt.Fprintf(&pkg.buf, format, args...)
214214
}
215215

@@ -235,7 +235,7 @@ func (pkg *Package) newlines(n int) {
235235
// clears the stuff we don't want to print anyway. It's a bit of a magic trick.
236236
func (pkg *Package) emit(comment string, node ast.Node) {
237237
if node != nil {
238-
var arg interface{} = node
238+
var arg any = node
239239
if showSrc {
240240
// Need an extra little dance to get internal comments to appear.
241241
arg = &printer.CommentedNode{

src/cmd/doc/testdata/nested/ignore.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build ignore
12
// +build ignore
23

34
// Ignored package

src/cmd/fix/cftype.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func typefix(f *ast.File, badType func(string) bool) bool {
4545

4646
// step 1: Find all the nils with the offending types.
4747
// Compute their replacement.
48-
badNils := map[interface{}]ast.Expr{}
49-
walk(f, func(n interface{}) {
48+
badNils := map[any]ast.Expr{}
49+
walk(f, func(n any) {
5050
if i, ok := n.(*ast.Ident); ok && i.Name == "nil" && badType(typeof[n]) {
5151
badNils[n] = &ast.BasicLit{ValuePos: i.NamePos, Kind: token.INT, Value: "0"}
5252
}
@@ -58,7 +58,7 @@ func typefix(f *ast.File, badType func(string) bool) bool {
5858
if len(badNils) > 0 {
5959
exprType := reflect.TypeOf((*ast.Expr)(nil)).Elem()
6060
exprSliceType := reflect.TypeOf(([]ast.Expr)(nil))
61-
walk(f, func(n interface{}) {
61+
walk(f, func(n any) {
6262
if n == nil {
6363
return
6464
}
@@ -99,7 +99,7 @@ func typefix(f *ast.File, badType func(string) bool) bool {
9999
// Now we need unsafe.Pointer as an intermediate cast.
100100
// (*unsafe.Pointer)(x) where x is type *bad -> (*unsafe.Pointer)(unsafe.Pointer(x))
101101
// (*bad.type)(x) where x is type *unsafe.Pointer -> (*bad.type)(unsafe.Pointer(x))
102-
walk(f, func(n interface{}) {
102+
walk(f, func(n any) {
103103
if n == nil {
104104
return
105105
}

src/cmd/fix/fix.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ func register(f fix) {
4343
// walk traverses the AST x, calling visit(y) for each node y in the tree but
4444
// also with a pointer to each ast.Expr, ast.Stmt, and *ast.BlockStmt,
4545
// in a bottom-up traversal.
46-
func walk(x interface{}, visit func(interface{})) {
46+
func walk(x any, visit func(any)) {
4747
walkBeforeAfter(x, nop, visit)
4848
}
4949

50-
func nop(interface{}) {}
50+
func nop(any) {}
5151

5252
// walkBeforeAfter is like walk but calls before(x) before traversing
5353
// x's children and after(x) afterward.
54-
func walkBeforeAfter(x interface{}, before, after func(interface{})) {
54+
func walkBeforeAfter(x any, before, after func(any)) {
5555
before(x)
5656

5757
switch n := x.(type) {
@@ -390,7 +390,7 @@ func renameTop(f *ast.File, old, new string) bool {
390390
// Rename top-level old to new, both unresolved names
391391
// (probably defined in another file) and names that resolve
392392
// to a declaration we renamed.
393-
walk(f, func(n interface{}) {
393+
walk(f, func(n any) {
394394
id, ok := n.(*ast.Ident)
395395
if ok && isTopName(id, old) {
396396
id.Name = new

src/cmd/fix/gotypes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func fixGoExact(f *ast.File) bool {
3636
// This one is harder because the import name changes.
3737
// First find the import spec.
3838
var importSpec *ast.ImportSpec
39-
walk(f, func(n interface{}) {
39+
walk(f, func(n any) {
4040
if importSpec != nil {
4141
return
4242
}

src/cmd/fix/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func processFile(filename string, useStdin bool) error {
245245
return os.WriteFile(f.Name(), newSrc, 0)
246246
}
247247

248-
func gofmt(n interface{}) string {
248+
func gofmt(n any) string {
249249
var gofmtBuf bytes.Buffer
250250
if err := format.Node(&gofmtBuf, fset, n); err != nil {
251251
return "<" + err.Error() + ">"

src/cmd/fix/netipv6zone.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func netipv6zone(f *ast.File) bool {
2626
}
2727

2828
fixed := false
29-
walk(f, func(n interface{}) {
29+
walk(f, func(n any) {
3030
cl, ok := n.(*ast.CompositeLit)
3131
if !ok {
3232
return

src/cmd/fix/printerconfig.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func printerconfig(f *ast.File) bool {
2323
}
2424

2525
fixed := false
26-
walk(f, func(n interface{}) {
26+
walk(f, func(n any) {
2727
cl, ok := n.(*ast.CompositeLit)
2828
if !ok {
2929
return

src/cmd/fix/typecheck.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ func (typ *Type) dot(cfg *TypeConfig, name string) string {
142142
// typeof maps AST nodes to type information in gofmt string form.
143143
// assign maps type strings to lists of expressions that were assigned
144144
// to values of another type that were assigned to that type.
145-
func typecheck(cfg *TypeConfig, f *ast.File) (typeof map[interface{}]string, assign map[string][]interface{}) {
146-
typeof = make(map[interface{}]string)
147-
assign = make(map[string][]interface{})
145+
func typecheck(cfg *TypeConfig, f *ast.File) (typeof map[any]string, assign map[string][]any) {
146+
typeof = make(map[any]string)
147+
assign = make(map[string][]any)
148148
cfg1 := &TypeConfig{}
149149
*cfg1 = *cfg // make copy so we can add locally
150150
copied := false
@@ -296,7 +296,7 @@ func makeExprList(a []*ast.Ident) []ast.Expr {
296296
// Typecheck1 is the recursive form of typecheck.
297297
// It is like typecheck but adds to the information in typeof
298298
// instead of allocating a new map.
299-
func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, assign map[string][]interface{}) {
299+
func typecheck1(cfg *TypeConfig, f any, typeof map[any]string, assign map[string][]any) {
300300
// set sets the type of n to typ.
301301
// If isDecl is true, n is being declared.
302302
set := func(n ast.Expr, typ string, isDecl bool) {
@@ -368,7 +368,7 @@ func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, a
368368
// the curfn stack.
369369
var curfn []*ast.FuncType
370370

371-
before := func(n interface{}) {
371+
before := func(n any) {
372372
// push function type on stack
373373
switch n := n.(type) {
374374
case *ast.FuncDecl:
@@ -379,7 +379,7 @@ func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, a
379379
}
380380

381381
// After is the real type checker.
382-
after := func(n interface{}) {
382+
after := func(n any) {
383383
if n == nil {
384384
return
385385
}

src/cmd/go/internal/base/base.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ func Exit() {
117117
os.Exit(exitStatus)
118118
}
119119

120-
func Fatalf(format string, args ...interface{}) {
120+
func Fatalf(format string, args ...any) {
121121
Errorf(format, args...)
122122
Exit()
123123
}
124124

125-
func Errorf(format string, args ...interface{}) {
125+
func Errorf(format string, args ...any) {
126126
log.Printf(format, args...)
127127
SetExitStatus(1)
128128
}
@@ -151,7 +151,7 @@ func GetExitStatus() int {
151151
// Run runs the command, with stdout and stderr
152152
// connected to the go command's own stdout and stderr.
153153
// If the command fails, Run reports the error using Errorf.
154-
func Run(cmdargs ...interface{}) {
154+
func Run(cmdargs ...any) {
155155
cmdline := str.StringList(cmdargs...)
156156
if cfg.BuildN || cfg.BuildX {
157157
fmt.Printf("%s\n", strings.Join(cmdline, " "))

src/cmd/go/internal/cmdflag/flag.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func ParseOne(fs *flag.FlagSet, args []string) (f *flag.Flag, remainingArgs []st
9292
// Use fs.Set instead of f.Value.Set below so that any subsequent call to
9393
// fs.Visit will correctly visit the flags that have been set.
9494

95-
failf := func(format string, a ...interface{}) (*flag.Flag, []string, error) {
95+
failf := func(format string, a ...any) (*flag.Flag, []string, error) {
9696
return f, args, fmt.Errorf(format, a...)
9797
}
9898

0 commit comments

Comments
 (0)