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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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
},

0 commit comments

Comments
 (0)