Skip to content

Commit 4bfc3a9

Browse files
adonovangopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent 2263d4a commit 4bfc3a9

File tree

99 files changed

+282
-284
lines changed

Some content is hidden

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

99 files changed

+282
-284
lines changed

src/cmd/asm/internal/asm/endtoend_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func testEndToEnd(t *testing.T, goarch, file string) {
3838
ctxt.IsAsm = true
3939
defer ctxt.Bso.Flush()
4040
failed := false
41-
ctxt.DiagFunc = func(format string, args ...interface{}) {
41+
ctxt.DiagFunc = func(format string, args ...any) {
4242
failed = true
4343
t.Errorf(format, args...)
4444
}
@@ -193,7 +193,7 @@ Diff:
193193
top := pList.Firstpc
194194
var text *obj.LSym
195195
ok = true
196-
ctxt.DiagFunc = func(format string, args ...interface{}) {
196+
ctxt.DiagFunc = func(format string, args ...any) {
197197
t.Errorf(format, args...)
198198
ok = false
199199
}
@@ -294,7 +294,7 @@ func testErrors(t *testing.T, goarch, file string, flags ...string) {
294294
failed := false
295295
var errBuf bytes.Buffer
296296
parser.errorWriter = &errBuf
297-
ctxt.DiagFunc = func(format string, args ...interface{}) {
297+
ctxt.DiagFunc = func(format string, args ...any) {
298298
failed = true
299299
s := fmt.Sprintf(format, args...)
300300
if !strings.HasSuffix(s, "\n") {

src/cmd/asm/internal/asm/parse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func NewParser(ctxt *obj.Link, ar *arch.Arch, lexer lex.TokenReader) *Parser {
7878
// and turn it into a recoverable panic.
7979
var panicOnError bool
8080

81-
func (p *Parser) errorf(format string, args ...interface{}) {
81+
func (p *Parser) errorf(format string, args ...any) {
8282
if panicOnError {
8383
panic(fmt.Errorf(format, args...))
8484
}
@@ -90,7 +90,7 @@ func (p *Parser) errorf(format string, args ...interface{}) {
9090
if p.lex != nil {
9191
// Put file and line information on head of message.
9292
format = "%s:%d: " + format + "\n"
93-
args = append([]interface{}{p.lex.File(), p.lineNum}, args...)
93+
args = append([]any{p.lex.File(), p.lineNum}, args...)
9494
}
9595
fmt.Fprintf(p.errorWriter, format, args...)
9696
p.errorCount++

src/cmd/asm/internal/lex/input.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func predefine(defines flags.MultiFlag) map[string]*Macro {
6868

6969
var panicOnError bool // For testing.
7070

71-
func (in *Input) Error(args ...interface{}) {
71+
func (in *Input) Error(args ...any) {
7272
if panicOnError {
7373
panic(fmt.Errorf("%s:%d: %s", in.File(), in.Line(), fmt.Sprintln(args...)))
7474
}
@@ -77,7 +77,7 @@ func (in *Input) Error(args ...interface{}) {
7777
}
7878

7979
// expectText is like Error but adds "got XXX" where XXX is a quoted representation of the most recent token.
80-
func (in *Input) expectText(args ...interface{}) {
80+
func (in *Input) expectText(args ...any) {
8181
in.Error(append(args, "; got", strconv.Quote(in.Stack.Text()))...)
8282
}
8383

src/cmd/asm/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func main() {
9393
for _, f := range flag.Args() {
9494
lexer := lex.NewLexer(f)
9595
parser := asm.NewParser(ctxt, architecture, lexer)
96-
ctxt.DiagFunc = func(format string, args ...interface{}) {
96+
ctxt.DiagFunc = func(format string, args ...any) {
9797
diag = true
9898
log.Printf(format, args...)
9999
}

src/cmd/cgo/ast.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func commentText(g *ast.CommentGroup) string {
199199
return strings.Join(pieces, "")
200200
}
201201

202-
func (f *File) validateIdents(x interface{}, context astContext) {
202+
func (f *File) validateIdents(x any, context astContext) {
203203
if x, ok := x.(*ast.Ident); ok {
204204
if f.isMangledName(x.Name) {
205205
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) {
208208
}
209209

210210
// Save various references we are going to need later.
211-
func (f *File) saveExprs(x interface{}, context astContext) {
211+
func (f *File) saveExprs(x any, context astContext) {
212212
switch x := x.(type) {
213213
case *ast.Expr:
214214
switch (*x).(type) {
@@ -278,7 +278,7 @@ func (f *File) saveCall(call *ast.CallExpr, context astContext) {
278278
}
279279

280280
// If a function should be exported add it to ExpFunc.
281-
func (f *File) saveExport(x interface{}, context astContext) {
281+
func (f *File) saveExport(x any, context astContext) {
282282
n, ok := x.(*ast.FuncDecl)
283283
if !ok {
284284
return
@@ -318,7 +318,7 @@ func (f *File) saveExport(x interface{}, context astContext) {
318318
}
319319

320320
// Make f.ExpFunc[i] point at the Func from this AST instead of the other one.
321-
func (f *File) saveExport2(x interface{}, context astContext) {
321+
func (f *File) saveExport2(x any, context astContext) {
322322
n, ok := x.(*ast.FuncDecl)
323323
if !ok {
324324
return
@@ -355,7 +355,7 @@ const (
355355
)
356356

357357
// walk walks the AST x, calling visit(f, x, context) for each node.
358-
func (f *File) walk(x interface{}, context astContext, visit func(*File, interface{}, astContext)) {
358+
func (f *File) walk(x any, context astContext, visit func(*File, any, astContext)) {
359359
visit(f, x, context)
360360
switch n := x.(type) {
361361
case *ast.Expr:

src/cmd/cgo/gcc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ func (p *Package) hasPointer(f *File, t ast.Expr, top bool) bool {
11581158
// If addPosition is true, add position info to the idents of C names in arg.
11591159
func (p *Package) mangle(f *File, arg *ast.Expr, addPosition bool) (ast.Expr, bool) {
11601160
needsUnsafe := false
1161-
f.walk(arg, ctxExpr, func(f *File, arg interface{}, context astContext) {
1161+
f.walk(arg, ctxExpr, func(f *File, arg any, context astContext) {
11621162
px, ok := arg.(*ast.Expr)
11631163
if !ok {
11641164
return
@@ -2439,7 +2439,7 @@ func (tr *TypeRepr) Empty() bool {
24392439
// Set modifies the type representation.
24402440
// If fargs are provided, repr is used as a format for fmt.Sprintf.
24412441
// Otherwise, repr is used unprocessed as the type representation.
2442-
func (tr *TypeRepr) Set(repr string, fargs ...interface{}) {
2442+
func (tr *TypeRepr) Set(repr string, fargs ...any) {
24432443
tr.Repr = repr
24442444
tr.FormatArgs = fargs
24452445
}
@@ -2713,7 +2713,7 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
27132713
// so execute the basic things that the struct case would do
27142714
// other than try to determine a Go representation.
27152715
tt := *t
2716-
tt.C = &TypeRepr{"%s %s", []interface{}{dt.Kind, tag}}
2716+
tt.C = &TypeRepr{"%s %s", []any{dt.Kind, tag}}
27172717
// We don't know what the representation of this struct is, so don't let
27182718
// anyone allocate one on the Go side. As a side effect of this annotation,
27192719
// 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
27432743
t.Align = align
27442744
tt := *t
27452745
if tag != "" {
2746-
tt.C = &TypeRepr{"struct %s", []interface{}{tag}}
2746+
tt.C = &TypeRepr{"struct %s", []any{tag}}
27472747
}
27482748
tt.Go = g
27492749
if c.incompleteStructs[tag] {

src/cmd/cgo/godefs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (p *Package) godefs(f *File, args []string) string {
117117
var gofmtBuf strings.Builder
118118

119119
// gofmt returns the gofmt-formatted string for an AST node.
120-
func gofmt(n interface{}) string {
120+
func gofmt(n any) string {
121121
gofmtBuf.Reset()
122122
err := printer.Fprint(&gofmtBuf, fset, n)
123123
if err != nil {

src/cmd/cgo/internal/testplugin/plugin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestMain(m *testing.M) {
3737
var tmpDir string
3838

3939
// prettyPrintf prints lines with tmpDir sanitized.
40-
func prettyPrintf(format string, args ...interface{}) {
40+
func prettyPrintf(format string, args ...any) {
4141
s := fmt.Sprintf(format, args...)
4242
if tmpDir != "" {
4343
s = strings.ReplaceAll(s, tmpDir, "$TMPDIR")

src/cmd/cgo/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ type ExpFunc struct {
148148
// A TypeRepr contains the string representation of a type.
149149
type TypeRepr struct {
150150
Repr string
151-
FormatArgs []interface{}
151+
FormatArgs []any
152152
}
153153

154154
// A Type collects information about a type in both the C and Go worlds.

src/cmd/cgo/out.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
953953
npad := 0
954954
// the align is at least 1 (for char)
955955
maxAlign := int64(1)
956-
argField := func(typ ast.Expr, namePat string, args ...interface{}) {
956+
argField := func(typ ast.Expr, namePat string, args ...any) {
957957
name := fmt.Sprintf(namePat, args...)
958958
t := p.cgoType(typ)
959959
if off%t.Align != 0 {
@@ -1412,7 +1412,7 @@ func forFieldList(fl *ast.FieldList, fn func(int, string, ast.Expr)) {
14121412
}
14131413
}
14141414

1415-
func c(repr string, args ...interface{}) *TypeRepr {
1415+
func c(repr string, args ...any) *TypeRepr {
14161416
return &TypeRepr{repr, args}
14171417
}
14181418

0 commit comments

Comments
 (0)