Skip to content

Commit 99337eb

Browse files
adonovangopherbot
authored andcommitted
x/tools: modernize interface{} -> any
Produced with a patched version of modernize containing only the efaceany pass: $ go run ./gopls/internal/analysis/modernize/cmd/modernize/main.go -test -fix ./... ./gopls/... This is very safe and forms the bulk of the modernize diff, isolating the other changes for ease of review. Change-Id: Iec9352bac5a639a5c03368427531c7842c6e9ad0 Reviewed-on: https://go-review.googlesource.com/c/tools/+/650759 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent 107c5b2 commit 99337eb

File tree

161 files changed

+630
-630
lines changed

Some content is hidden

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

161 files changed

+630
-630
lines changed

blog/blog.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ type rootData struct {
420420
BasePath string
421421
GodocURL string
422422
AnalyticsHTML template.HTML
423-
Data interface{}
423+
Data any
424424
}
425425

426426
// ServeHTTP serves the front, index, and article pages

container/intsets/sparse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (s *Sparse) init() {
267267
// loop. Fail fast before this occurs.
268268
// We don't want to call panic here because it prevents the
269269
// inlining of this function.
270-
_ = (interface{}(nil)).(to_copy_a_sparse_you_must_call_its_Copy_method)
270+
_ = (any(nil)).(to_copy_a_sparse_you_must_call_its_Copy_method)
271271
}
272272
}
273273

go/analysis/analysis.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type Analyzer struct {
4545
// To pass analysis results between packages (and thus
4646
// potentially between address spaces), use Facts, which are
4747
// serializable.
48-
Run func(*Pass) (interface{}, error)
48+
Run func(*Pass) (any, error)
4949

5050
// RunDespiteErrors allows the driver to invoke
5151
// the Run method of this analyzer even on a
@@ -112,7 +112,7 @@ type Pass struct {
112112
// The map keys are the elements of Analysis.Required,
113113
// and the type of each corresponding value is the required
114114
// analysis's ResultType.
115-
ResultOf map[*Analyzer]interface{}
115+
ResultOf map[*Analyzer]any
116116

117117
// ReadFile returns the contents of the named file.
118118
//
@@ -186,7 +186,7 @@ type ObjectFact struct {
186186

187187
// Reportf is a helper function that reports a Diagnostic using the
188188
// specified position and formatted error message.
189-
func (pass *Pass) Reportf(pos token.Pos, format string, args ...interface{}) {
189+
func (pass *Pass) Reportf(pos token.Pos, format string, args ...any) {
190190
msg := fmt.Sprintf(format, args...)
191191
pass.Report(Diagnostic{Pos: pos, Message: msg})
192192
}
@@ -201,7 +201,7 @@ type Range interface {
201201
// ReportRangef is a helper function that reports a Diagnostic using the
202202
// range provided. ast.Node values can be passed in as the range because
203203
// they satisfy the Range interface.
204-
func (pass *Pass) ReportRangef(rng Range, format string, args ...interface{}) {
204+
func (pass *Pass) ReportRangef(rng Range, format string, args ...any) {
205205
msg := fmt.Sprintf(format, args...)
206206
pass.Report(Diagnostic{Pos: rng.Pos(), End: rng.End(), Message: msg})
207207
}

go/analysis/analysistest/analysistest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var TestData = func() string {
7676

7777
// Testing is an abstraction of a *testing.T.
7878
type Testing interface {
79-
Errorf(format string, args ...interface{})
79+
Errorf(format string, args ...any)
8080
}
8181

8282
// RunWithSuggestedFixes behaves like Run, but additionally applies

go/analysis/analysistest/analysistest_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,6 @@ type T string
262262

263263
type errorfunc func(string)
264264

265-
func (f errorfunc) Errorf(format string, args ...interface{}) {
265+
func (f errorfunc) Errorf(format string, args ...any) {
266266
f(fmt.Sprintf(format, args...))
267267
}

go/analysis/internal/analysisflags/flags.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func addVersionFlag() {
201201
type versionFlag struct{}
202202

203203
func (versionFlag) IsBoolFlag() bool { return true }
204-
func (versionFlag) Get() interface{} { return nil }
204+
func (versionFlag) Get() any { return nil }
205205
func (versionFlag) String() string { return "" }
206206
func (versionFlag) Set(s string) error {
207207
if s != "full" {
@@ -252,7 +252,7 @@ const (
252252

253253
// triState implements flag.Value, flag.Getter, and flag.boolFlag.
254254
// They work like boolean flags: we can say vet -printf as well as vet -printf=true
255-
func (ts *triState) Get() interface{} {
255+
func (ts *triState) Get() any {
256256
return *ts == setTrue
257257
}
258258

@@ -340,7 +340,7 @@ func PrintPlain(out io.Writer, fset *token.FileSet, contextLines int, diag analy
340340

341341
// A JSONTree is a mapping from package ID to analysis name to result.
342342
// Each result is either a jsonError or a list of JSONDiagnostic.
343-
type JSONTree map[string]map[string]interface{}
343+
type JSONTree map[string]map[string]any
344344

345345
// A TextEdit describes the replacement of a portion of a file.
346346
// Start and End are zero-based half-open indices into the original byte
@@ -383,7 +383,7 @@ type JSONRelatedInformation struct {
383383
// Add adds the result of analysis 'name' on package 'id'.
384384
// The result is either a list of diagnostics or an error.
385385
func (tree JSONTree) Add(fset *token.FileSet, id, name string, diags []analysis.Diagnostic, err error) {
386-
var v interface{}
386+
var v any
387387
if err != nil {
388388
type jsonError struct {
389389
Err string `json:"error"`
@@ -429,7 +429,7 @@ func (tree JSONTree) Add(fset *token.FileSet, id, name string, diags []analysis.
429429
if v != nil {
430430
m, ok := tree[id]
431431
if !ok {
432-
m = make(map[string]interface{})
432+
m = make(map[string]any)
433433
tree[id] = m
434434
}
435435
m[name] = v

go/analysis/internal/checker/checker_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func NewT1() *T1 { return &T1{T} }
107107
Name: "noop",
108108
Doc: "noop",
109109
Requires: []*analysis.Analyzer{inspect.Analyzer},
110-
Run: func(pass *analysis.Pass) (interface{}, error) {
110+
Run: func(pass *analysis.Pass) (any, error) {
111111
return nil, nil
112112
},
113113
RunDespiteErrors: true,
@@ -119,7 +119,7 @@ func NewT1() *T1 { return &T1{T} }
119119
Name: "noopfact",
120120
Doc: "noopfact",
121121
Requires: []*analysis.Analyzer{inspect.Analyzer},
122-
Run: func(pass *analysis.Pass) (interface{}, error) {
122+
Run: func(pass *analysis.Pass) (any, error) {
123123
return nil, nil
124124
},
125125
RunDespiteErrors: true,
@@ -185,7 +185,7 @@ func TestURL(t *testing.T) {
185185
Name: "pkgname",
186186
Doc: "trivial analyzer that reports package names",
187187
URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/internal/checker",
188-
Run: func(p *analysis.Pass) (interface{}, error) {
188+
Run: func(p *analysis.Pass) (any, error) {
189189
for _, f := range p.Files {
190190
p.ReportRangef(f.Name, "package name is %s", f.Name.Name)
191191
}

go/analysis/internal/checker/start_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var commentAnalyzer = &analysis.Analyzer{
6262
Run: commentRun,
6363
}
6464

65-
func commentRun(pass *analysis.Pass) (interface{}, error) {
65+
func commentRun(pass *analysis.Pass) (any, error) {
6666
const (
6767
from = "/* Package comment */"
6868
to = "// Package comment"

go/analysis/internal/internal.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ import "golang.org/x/tools/go/analysis"
99
// This function is set by the checker package to provide
1010
// backdoor access to the private Pass field
1111
// of the checker.Action type, for use by analysistest.
12-
var Pass func(interface{}) *analysis.Pass
12+
var Pass func(any) *analysis.Pass

go/analysis/internal/versiontest/version_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
var analyzer = &analysis.Analyzer{
2727
Name: "versiontest",
2828
Doc: "off",
29-
Run: func(pass *analysis.Pass) (interface{}, error) {
29+
Run: func(pass *analysis.Pass) (any, error) {
3030
pass.Reportf(pass.Files[0].Package, "goversion=%s", pass.Pkg.GoVersion())
3131
return nil, nil
3232
},

go/analysis/multichecker/multichecker_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func main() {
2323
fail := &analysis.Analyzer{
2424
Name: "fail",
2525
Doc: "always fail on a package 'sort'",
26-
Run: func(pass *analysis.Pass) (interface{}, error) {
26+
Run: func(pass *analysis.Pass) (any, error) {
2727
if pass.Pkg.Path() == "sort" {
2828
return nil, fmt.Errorf("failed")
2929
}

go/analysis/passes/appends/appends.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var Analyzer = &analysis.Analyzer{
2929
Run: run,
3030
}
3131

32-
func run(pass *analysis.Pass) (interface{}, error) {
32+
func run(pass *analysis.Pass) (any, error) {
3333
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
3434

3535
nodeFilter := []ast.Node{

go/analysis/passes/asmdecl/asmdecl.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ var (
150150
abiSuff = re(`^(.+)<(ABI.+)>$`)
151151
)
152152

153-
func run(pass *analysis.Pass) (interface{}, error) {
153+
func run(pass *analysis.Pass) (any, error) {
154154
// No work if no assembly files.
155155
var sfiles []string
156156
for _, fname := range pass.OtherFiles {
@@ -226,7 +226,7 @@ Files:
226226
for lineno, line := range lines {
227227
lineno++
228228

229-
badf := func(format string, args ...interface{}) {
229+
badf := func(format string, args ...any) {
230230
pass.Reportf(analysisutil.LineStart(tf, lineno), "[%s] %s: %s", arch, fnName, fmt.Sprintf(format, args...))
231231
}
232232

@@ -646,7 +646,7 @@ func asmParseDecl(pass *analysis.Pass, decl *ast.FuncDecl) map[string]*asmFunc {
646646
}
647647

648648
// asmCheckVar checks a single variable reference.
649-
func asmCheckVar(badf func(string, ...interface{}), fn *asmFunc, line, expr string, off int, v *asmVar, archDef *asmArch) {
649+
func asmCheckVar(badf func(string, ...any), fn *asmFunc, line, expr string, off int, v *asmVar, archDef *asmArch) {
650650
m := asmOpcode.FindStringSubmatch(line)
651651
if m == nil {
652652
if !strings.HasPrefix(strings.TrimSpace(line), "//") {

go/analysis/passes/buildssa/buildssa.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type SSA struct {
3232
SrcFuncs []*ssa.Function
3333
}
3434

35-
func run(pass *analysis.Pass) (interface{}, error) {
35+
func run(pass *analysis.Pass) (any, error) {
3636
// We must create a new Program for each Package because the
3737
// analysis API provides no place to hang a Program shared by
3838
// all Packages. Consequently, SSA Packages and Functions do not

go/analysis/passes/buildtag/buildtag.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var Analyzer = &analysis.Analyzer{
2626
Run: runBuildTag,
2727
}
2828

29-
func runBuildTag(pass *analysis.Pass) (interface{}, error) {
29+
func runBuildTag(pass *analysis.Pass) (any, error) {
3030
for _, f := range pass.Files {
3131
checkGoFile(pass, f)
3232
}

go/analysis/passes/cgocall/cgocall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func run(pass *analysis.Pass) (any, error) {
5555
return nil, nil
5656
}
5757

58-
func checkCgo(fset *token.FileSet, f *ast.File, info *types.Info, reportf func(token.Pos, string, ...interface{})) {
58+
func checkCgo(fset *token.FileSet, f *ast.File, info *types.Info, reportf func(token.Pos, string, ...any)) {
5959
ast.Inspect(f, func(n ast.Node) bool {
6060
call, ok := n.(*ast.CallExpr)
6161
if !ok {

go/analysis/passes/composite/composite.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func init() {
5151

5252
// runUnkeyedLiteral checks if a composite literal is a struct literal with
5353
// unkeyed fields.
54-
func run(pass *analysis.Pass) (interface{}, error) {
54+
func run(pass *analysis.Pass) (any, error) {
5555
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
5656

5757
nodeFilter := []ast.Node{

go/analysis/passes/copylock/copylock.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var Analyzer = &analysis.Analyzer{
3636
Run: run,
3737
}
3838

39-
func run(pass *analysis.Pass) (interface{}, error) {
39+
func run(pass *analysis.Pass) (any, error) {
4040
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
4141

4242
var goversion string // effective file version ("" => unknown)

go/analysis/passes/ctrlflow/ctrlflow.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (c *CFGs) FuncLit(lit *ast.FuncLit) *cfg.CFG {
8080
return c.funcLits[lit].cfg
8181
}
8282

83-
func run(pass *analysis.Pass) (interface{}, error) {
83+
func run(pass *analysis.Pass) (any, error) {
8484
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
8585

8686
// Because CFG construction consumes and produces noReturn

go/analysis/passes/directive/directive.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var Analyzer = &analysis.Analyzer{
4040
Run: runDirective,
4141
}
4242

43-
func runDirective(pass *analysis.Pass) (interface{}, error) {
43+
func runDirective(pass *analysis.Pass) (any, error) {
4444
for _, f := range pass.Files {
4545
checkGoFile(pass, f)
4646
}

go/analysis/passes/fieldalignment/fieldalignment.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var Analyzer = &analysis.Analyzer{
6565
Run: run,
6666
}
6767

68-
func run(pass *analysis.Pass) (interface{}, error) {
68+
func run(pass *analysis.Pass) (any, error) {
6969
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
7070
nodeFilter := []ast.Node{
7171
(*ast.StructType)(nil),

go/analysis/passes/findcall/findcall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func init() {
3838
Analyzer.Flags.StringVar(&name, "name", name, "name of the function to find")
3939
}
4040

41-
func run(pass *analysis.Pass) (interface{}, error) {
41+
func run(pass *analysis.Pass) (any, error) {
4242
for _, f := range pass.Files {
4343
ast.Inspect(f, func(n ast.Node) bool {
4444
if call, ok := n.(*ast.CallExpr); ok {

go/analysis/passes/framepointer/framepointer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ var arm64Branch = map[string]bool{
113113
"RET": true,
114114
}
115115

116-
func run(pass *analysis.Pass) (interface{}, error) {
116+
func run(pass *analysis.Pass) (any, error) {
117117
arch, ok := arches[build.Default.GOARCH]
118118
if !ok {
119119
return nil, nil

go/analysis/passes/ifaceassert/ifaceassert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func assertableTo(free *typeparams.Free, v, t types.Type) *types.Func {
5252
return nil
5353
}
5454

55-
func run(pass *analysis.Pass) (interface{}, error) {
55+
func run(pass *analysis.Pass) (any, error) {
5656
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
5757
nodeFilter := []ast.Node{
5858
(*ast.TypeAssertExpr)(nil),

go/analysis/passes/inspect/inspect.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ var Analyzer = &analysis.Analyzer{
4444
ResultType: reflect.TypeOf(new(inspector.Inspector)),
4545
}
4646

47-
func run(pass *analysis.Pass) (interface{}, error) {
47+
func run(pass *analysis.Pass) (any, error) {
4848
return inspector.New(pass.Files), nil
4949
}

go/analysis/passes/loopclosure/loopclosure.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var Analyzer = &analysis.Analyzer{
3030
Run: run,
3131
}
3232

33-
func run(pass *analysis.Pass) (interface{}, error) {
33+
func run(pass *analysis.Pass) (any, error) {
3434
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
3535

3636
nodeFilter := []ast.Node{

go/analysis/passes/lostcancel/lostcancel.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var contextPackage = "context"
4747
// containing the assignment, we assume that other uses exist.
4848
//
4949
// checkLostCancel analyzes a single named or literal function.
50-
func run(pass *analysis.Pass) (interface{}, error) {
50+
func run(pass *analysis.Pass) (any, error) {
5151
// Fast path: bypass check if file doesn't use context.WithCancel.
5252
if !analysisinternal.Imports(pass.Pkg, contextPackage) {
5353
return nil, nil

go/analysis/passes/nilfunc/nilfunc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var Analyzer = &analysis.Analyzer{
3030
Run: run,
3131
}
3232

33-
func run(pass *analysis.Pass) (interface{}, error) {
33+
func run(pass *analysis.Pass) (any, error) {
3434
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
3535

3636
nodeFilter := []ast.Node{

go/analysis/passes/nilness/nilness.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var Analyzer = &analysis.Analyzer{
2828
Requires: []*analysis.Analyzer{buildssa.Analyzer},
2929
}
3030

31-
func run(pass *analysis.Pass) (interface{}, error) {
31+
func run(pass *analysis.Pass) (any, error) {
3232
ssainput := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA)
3333
for _, fn := range ssainput.SrcFuncs {
3434
runFunc(pass, fn)
@@ -37,7 +37,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
3737
}
3838

3939
func runFunc(pass *analysis.Pass, fn *ssa.Function) {
40-
reportf := func(category string, pos token.Pos, format string, args ...interface{}) {
40+
reportf := func(category string, pos token.Pos, format string, args ...any) {
4141
// We ignore nil-checking ssa.Instructions
4242
// that don't correspond to syntax.
4343
if pos.IsValid() {

go/analysis/passes/pkgfact/pkgfact.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type pairsFact []string
5353
func (f *pairsFact) AFact() {}
5454
func (f *pairsFact) String() string { return "pairs(" + strings.Join(*f, ", ") + ")" }
5555

56-
func run(pass *analysis.Pass) (interface{}, error) {
56+
func run(pass *analysis.Pass) (any, error) {
5757
result := make(map[string]string)
5858

5959
// At each import, print the fact from the imported

go/analysis/passes/reflectvaluecompare/reflectvaluecompare.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var Analyzer = &analysis.Analyzer{
2828
Run: run,
2929
}
3030

31-
func run(pass *analysis.Pass) (interface{}, error) {
31+
func run(pass *analysis.Pass) (any, error) {
3232
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
3333

3434
nodeFilter := []ast.Node{

go/analysis/passes/shadow/shadow.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func init() {
3636
Analyzer.Flags.BoolVar(&strict, "strict", strict, "whether to be strict about shadowing; can be noisy")
3737
}
3838

39-
func run(pass *analysis.Pass) (interface{}, error) {
39+
func run(pass *analysis.Pass) (any, error) {
4040
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
4141

4242
spans := make(map[types.Object]span)

go/analysis/passes/shift/shift.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var Analyzer = &analysis.Analyzer{
3434
Run: run,
3535
}
3636

37-
func run(pass *analysis.Pass) (interface{}, error) {
37+
func run(pass *analysis.Pass) (any, error) {
3838
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
3939

4040
// Do a complete pass to compute dead nodes.

0 commit comments

Comments
 (0)