diff options
| author | Alan Donovan <adonovan@google.com> | 2025-11-11 14:48:22 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-11-11 19:59:40 -0800 |
| commit | 4bfc3a9d14c0b3bfcfe4ce987e47cda6720785a2 (patch) | |
| tree | 0cbf1ec55d3a61af8bf45ac4a00af7e7bcc426db /src/cmd/cgo | |
| parent | 2263d4aabdde8a4a466009ecc356501f87c7efb7 (diff) | |
| download | go-4bfc3a9d14c0b3bfcfe4ce987e47cda6720785a2.tar.xz | |
std,cmd: go fix -any std cmd
This change mechanically replaces all occurrences of interface{}
by 'any' (where deemed safe by the 'any' modernizer) throughout
std and cmd, minus their vendor trees.
Since this fix is relatively numerous, it gets its own CL.
Also, 'go generate go/types'.
Change-Id: I14a6b52856c3291c1d27935409bca8d5fd4242a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/719702
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/cmd/cgo')
| -rw-r--r-- | src/cmd/cgo/ast.go | 10 | ||||
| -rw-r--r-- | src/cmd/cgo/gcc.go | 8 | ||||
| -rw-r--r-- | src/cmd/cgo/godefs.go | 2 | ||||
| -rw-r--r-- | src/cmd/cgo/internal/testplugin/plugin_test.go | 2 | ||||
| -rw-r--r-- | src/cmd/cgo/main.go | 2 | ||||
| -rw-r--r-- | src/cmd/cgo/out.go | 4 | ||||
| -rw-r--r-- | src/cmd/cgo/util.go | 4 |
7 files changed, 16 insertions, 16 deletions
diff --git a/src/cmd/cgo/ast.go b/src/cmd/cgo/ast.go index 97b18cd22d..2da6ca5a30 100644 --- a/src/cmd/cgo/ast.go +++ b/src/cmd/cgo/ast.go @@ -199,7 +199,7 @@ func commentText(g *ast.CommentGroup) string { return strings.Join(pieces, "") } -func (f *File) validateIdents(x interface{}, context astContext) { +func (f *File) validateIdents(x any, context astContext) { if x, ok := x.(*ast.Ident); ok { if f.isMangledName(x.Name) { error_(x.Pos(), "identifier %q may conflict with identifiers generated by cgo", x.Name) @@ -208,7 +208,7 @@ func (f *File) validateIdents(x interface{}, context astContext) { } // Save various references we are going to need later. -func (f *File) saveExprs(x interface{}, context astContext) { +func (f *File) saveExprs(x any, context astContext) { switch x := x.(type) { case *ast.Expr: switch (*x).(type) { @@ -278,7 +278,7 @@ func (f *File) saveCall(call *ast.CallExpr, context astContext) { } // If a function should be exported add it to ExpFunc. -func (f *File) saveExport(x interface{}, context astContext) { +func (f *File) saveExport(x any, context astContext) { n, ok := x.(*ast.FuncDecl) if !ok { return @@ -318,7 +318,7 @@ func (f *File) saveExport(x interface{}, context astContext) { } // Make f.ExpFunc[i] point at the Func from this AST instead of the other one. -func (f *File) saveExport2(x interface{}, context astContext) { +func (f *File) saveExport2(x any, context astContext) { n, ok := x.(*ast.FuncDecl) if !ok { return @@ -355,7 +355,7 @@ const ( ) // walk walks the AST x, calling visit(f, x, context) for each node. -func (f *File) walk(x interface{}, context astContext, visit func(*File, interface{}, astContext)) { +func (f *File) walk(x any, context astContext, visit func(*File, any, astContext)) { visit(f, x, context) switch n := x.(type) { case *ast.Expr: diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index d1b629057a..d3de3906b4 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -1158,7 +1158,7 @@ func (p *Package) hasPointer(f *File, t ast.Expr, top bool) bool { // If addPosition is true, add position info to the idents of C names in arg. func (p *Package) mangle(f *File, arg *ast.Expr, addPosition bool) (ast.Expr, bool) { needsUnsafe := false - f.walk(arg, ctxExpr, func(f *File, arg interface{}, context astContext) { + f.walk(arg, ctxExpr, func(f *File, arg any, context astContext) { px, ok := arg.(*ast.Expr) if !ok { return @@ -2439,7 +2439,7 @@ func (tr *TypeRepr) Empty() bool { // Set modifies the type representation. // If fargs are provided, repr is used as a format for fmt.Sprintf. // Otherwise, repr is used unprocessed as the type representation. -func (tr *TypeRepr) Set(repr string, fargs ...interface{}) { +func (tr *TypeRepr) Set(repr string, fargs ...any) { tr.Repr = repr tr.FormatArgs = fargs } @@ -2713,7 +2713,7 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ // so execute the basic things that the struct case would do // other than try to determine a Go representation. tt := *t - tt.C = &TypeRepr{"%s %s", []interface{}{dt.Kind, tag}} + tt.C = &TypeRepr{"%s %s", []any{dt.Kind, tag}} // We don't know what the representation of this struct is, so don't let // anyone allocate one on the Go side. As a side effect of this annotation, // pointers to this type will not be considered pointers in Go. They won't @@ -2743,7 +2743,7 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ t.Align = align tt := *t if tag != "" { - tt.C = &TypeRepr{"struct %s", []interface{}{tag}} + tt.C = &TypeRepr{"struct %s", []any{tag}} } tt.Go = g if c.incompleteStructs[tag] { diff --git a/src/cmd/cgo/godefs.go b/src/cmd/cgo/godefs.go index 9cf626c173..93f9027157 100644 --- a/src/cmd/cgo/godefs.go +++ b/src/cmd/cgo/godefs.go @@ -117,7 +117,7 @@ func (p *Package) godefs(f *File, args []string) string { var gofmtBuf strings.Builder // gofmt returns the gofmt-formatted string for an AST node. -func gofmt(n interface{}) string { +func gofmt(n any) string { gofmtBuf.Reset() err := printer.Fprint(&gofmtBuf, fset, n) if err != nil { diff --git a/src/cmd/cgo/internal/testplugin/plugin_test.go b/src/cmd/cgo/internal/testplugin/plugin_test.go index 2afb542ec4..3216073edb 100644 --- a/src/cmd/cgo/internal/testplugin/plugin_test.go +++ b/src/cmd/cgo/internal/testplugin/plugin_test.go @@ -37,7 +37,7 @@ func TestMain(m *testing.M) { var tmpDir string // prettyPrintf prints lines with tmpDir sanitized. -func prettyPrintf(format string, args ...interface{}) { +func prettyPrintf(format string, args ...any) { s := fmt.Sprintf(format, args...) if tmpDir != "" { s = strings.ReplaceAll(s, tmpDir, "$TMPDIR") diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go index 955d64b956..ba8e52a6e0 100644 --- a/src/cmd/cgo/main.go +++ b/src/cmd/cgo/main.go @@ -148,7 +148,7 @@ type ExpFunc struct { // A TypeRepr contains the string representation of a type. type TypeRepr struct { Repr string - FormatArgs []interface{} + FormatArgs []any } // A Type collects information about a type in both the C and Go worlds. diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index f0e07284ec..701a8530ff 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -953,7 +953,7 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) { npad := 0 // the align is at least 1 (for char) maxAlign := int64(1) - argField := func(typ ast.Expr, namePat string, args ...interface{}) { + argField := func(typ ast.Expr, namePat string, args ...any) { name := fmt.Sprintf(namePat, args...) t := p.cgoType(typ) if off%t.Align != 0 { @@ -1412,7 +1412,7 @@ func forFieldList(fl *ast.FieldList, fn func(int, string, ast.Expr)) { } } -func c(repr string, args ...interface{}) *TypeRepr { +func c(repr string, args ...any) *TypeRepr { return &TypeRepr{repr, args} } diff --git a/src/cmd/cgo/util.go b/src/cmd/cgo/util.go index 23b4a414db..e83634ffb2 100644 --- a/src/cmd/cgo/util.go +++ b/src/cmd/cgo/util.go @@ -75,7 +75,7 @@ func lineno(pos token.Pos) string { } // Die with an error message. -func fatalf(msg string, args ...interface{}) { +func fatalf(msg string, args ...any) { // If we've already printed other errors, they might have // caused the fatal condition. Assume they're enough. if nerrors == 0 { @@ -86,7 +86,7 @@ func fatalf(msg string, args ...interface{}) { var nerrors int -func error_(pos token.Pos, msg string, args ...interface{}) { +func error_(pos token.Pos, msg string, args ...any) { nerrors++ if pos.IsValid() { fmt.Fprintf(os.Stderr, "%s: ", fset.Position(pos).String()) |
