aboutsummaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-12-01 12:15:45 -0500
committerRuss Cox <rsc@golang.org>2021-12-13 18:45:54 +0000
commit2580d0e08d5e9f979b943758d3c49877fb2324cb (patch)
tree3aafccfd81087734156a1778ce2321adf345f271 /src/internal
parent083ef5462494e81ee23316245c5d65085a3f62d9 (diff)
downloadgo-2580d0e08d5e9f979b943758d3c49877fb2324cb.tar.gz
go-2580d0e08d5e9f979b943758d3c49877fb2324cb.zip
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>
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/abi/abi.go4
-rw-r--r--src/internal/fmtsort/sort_test.go14
-rw-r--r--src/internal/fuzz/encoding.go12
-rw-r--r--src/internal/fuzz/fuzz.go14
-rw-r--r--src/internal/fuzz/minimize_test.go34
-rw-r--r--src/internal/fuzz/mutator.go2
-rw-r--r--src/internal/fuzz/mutator_test.go10
-rw-r--r--src/internal/fuzz/queue.go10
-rw-r--r--src/internal/fuzz/worker.go10
-rw-r--r--src/internal/fuzz/worker_test.go6
-rw-r--r--src/internal/intern/intern.go10
-rw-r--r--src/internal/lazytemplate/lazytemplate.go2
-rw-r--r--src/internal/nettrace/nettrace.go2
-rw-r--r--src/internal/poll/splice_linux.go2
-rw-r--r--src/internal/poll/splice_linux_test.go2
-rw-r--r--src/internal/reflectlite/all_test.go32
-rw-r--r--src/internal/reflectlite/export_test.go2
-rw-r--r--src/internal/reflectlite/set_test.go12
-rw-r--r--src/internal/reflectlite/swapper.go2
-rw-r--r--src/internal/reflectlite/type.go2
-rw-r--r--src/internal/reflectlite/value.go26
-rw-r--r--src/internal/singleflight/singleflight.go10
-rw-r--r--src/internal/singleflight/singleflight_test.go6
-rw-r--r--src/internal/syscall/windows/registry/registry_test.go2
-rw-r--r--src/internal/trace/gc.go8
-rw-r--r--src/internal/unsafeheader/unsafeheader_test.go2
26 files changed, 119 insertions, 119 deletions
diff --git a/src/internal/abi/abi.go b/src/internal/abi/abi.go
index b266a7ff78..11acac346f 100644
--- a/src/internal/abi/abi.go
+++ b/src/internal/abi/abi.go
@@ -114,7 +114,7 @@ func (b *IntArgRegBitmap) Get(i int) bool {
// compile-time error.
//
// Implemented as a compile intrinsic.
-func FuncPCABI0(f interface{}) uintptr
+func FuncPCABI0(f any) uintptr
// FuncPCABIInternal returns the entry PC of the function f. If f is a
// direct reference of a function, it must be defined as ABIInternal.
@@ -123,4 +123,4 @@ func FuncPCABI0(f interface{}) uintptr
// the behavior is undefined.
//
// Implemented as a compile intrinsic.
-func FuncPCABIInternal(f interface{}) uintptr
+func FuncPCABIInternal(f any) uintptr
diff --git a/src/internal/fmtsort/sort_test.go b/src/internal/fmtsort/sort_test.go
index ab063af5ba..11befca6f1 100644
--- a/src/internal/fmtsort/sort_test.go
+++ b/src/internal/fmtsort/sort_test.go
@@ -38,12 +38,12 @@ var compareTests = [][]reflect.Value{
ct(reflect.TypeOf(chans[0]), chans[0], chans[1], chans[2]),
ct(reflect.TypeOf(toy{}), toy{0, 1}, toy{0, 2}, toy{1, -1}, toy{1, 1}),
ct(reflect.TypeOf([2]int{}), [2]int{1, 1}, [2]int{1, 2}, [2]int{2, 0}),
- ct(reflect.TypeOf(interface{}(interface{}(0))), iFace, 1, 2, 3),
+ ct(reflect.TypeOf(any(any(0))), iFace, 1, 2, 3),
}
-var iFace interface{}
+var iFace any
-func ct(typ reflect.Type, args ...interface{}) []reflect.Value {
+func ct(typ reflect.Type, args ...any) []reflect.Value {
value := make([]reflect.Value, len(args))
for i, v := range args {
x := reflect.ValueOf(v)
@@ -84,8 +84,8 @@ func TestCompare(t *testing.T) {
}
type sortTest struct {
- data interface{} // Always a map.
- print string // Printed result using our custom printer.
+ data any // Always a map.
+ print string // Printed result using our custom printer.
}
var sortTests = []sortTest{
@@ -135,7 +135,7 @@ var sortTests = []sortTest{
},
}
-func sprint(data interface{}) string {
+func sprint(data any) string {
om := fmtsort.Sort(reflect.ValueOf(data))
if om == nil {
return "nil"
@@ -244,7 +244,7 @@ func TestInterface(t *testing.T) {
// A map containing multiple concrete types should be sorted by type,
// then value. However, the relative ordering of types is unspecified,
// so test this by checking the presence of sorted subgroups.
- m := map[interface{}]string{
+ m := map[any]string{
[2]int{1, 0}: "",
[2]int{0, 1}: "",
true: "",
diff --git a/src/internal/fuzz/encoding.go b/src/internal/fuzz/encoding.go
index d3f24c3e6c..2bfa02b8c0 100644
--- a/src/internal/fuzz/encoding.go
+++ b/src/internal/fuzz/encoding.go
@@ -18,7 +18,7 @@ var encVersion1 = "go test fuzz v1"
// marshalCorpusFile encodes an arbitrary number of arguments into the file format for the
// corpus.
-func marshalCorpusFile(vals ...interface{}) []byte {
+func marshalCorpusFile(vals ...any) []byte {
if len(vals) == 0 {
panic("must have at least one value to marshal")
}
@@ -45,7 +45,7 @@ func marshalCorpusFile(vals ...interface{}) []byte {
}
// unmarshalCorpusFile decodes corpus bytes into their respective values.
-func unmarshalCorpusFile(b []byte) ([]interface{}, error) {
+func unmarshalCorpusFile(b []byte) ([]any, error) {
if len(b) == 0 {
return nil, fmt.Errorf("cannot unmarshal empty string")
}
@@ -56,7 +56,7 @@ func unmarshalCorpusFile(b []byte) ([]interface{}, error) {
if string(lines[0]) != encVersion1 {
return nil, fmt.Errorf("unknown encoding version: %s", lines[0])
}
- var vals []interface{}
+ var vals []any
for _, line := range lines[1:] {
line = bytes.TrimSpace(line)
if len(line) == 0 {
@@ -71,7 +71,7 @@ func unmarshalCorpusFile(b []byte) ([]interface{}, error) {
return vals, nil
}
-func parseCorpusValue(line []byte) (interface{}, error) {
+func parseCorpusValue(line []byte) (any, error) {
fs := token.NewFileSet()
expr, err := parser.ParseExprFrom(fs, "(test)", line, 0)
if err != nil {
@@ -197,7 +197,7 @@ func parseCorpusValue(line []byte) (interface{}, error) {
}
// parseInt returns an integer of value val and type typ.
-func parseInt(val, typ string) (interface{}, error) {
+func parseInt(val, typ string) (any, error) {
switch typ {
case "int":
return strconv.Atoi(val)
@@ -218,7 +218,7 @@ func parseInt(val, typ string) (interface{}, error) {
}
// parseInt returns an unsigned integer of value val and type typ.
-func parseUint(val, typ string) (interface{}, error) {
+func parseUint(val, typ string) (any, error) {
switch typ {
case "uint":
i, err := strconv.ParseUint(val, 10, 0)
diff --git a/src/internal/fuzz/fuzz.go b/src/internal/fuzz/fuzz.go
index cb739232c7..b3f1381dbb 100644
--- a/src/internal/fuzz/fuzz.go
+++ b/src/internal/fuzz/fuzz.go
@@ -455,7 +455,7 @@ type CorpusEntry = struct {
Data []byte
// Values is the unmarshaled values from a corpus file.
- Values []interface{}
+ Values []any
Generation int
@@ -684,7 +684,7 @@ func newCoordinator(opts CoordinateFuzzingOpts) (*coordinator, error) {
if len(c.corpus.entries) == 0 {
fmt.Fprintf(c.opts.Log, "warning: starting with empty corpus\n")
- var vals []interface{}
+ var vals []any
for _, t := range opts.Types {
vals = append(vals, zeroValue(t))
}
@@ -968,7 +968,7 @@ func ReadCorpus(dir string, types []reflect.Type) ([]CorpusEntry, error) {
if err != nil {
return nil, fmt.Errorf("failed to read corpus file: %v", err)
}
- var vals []interface{}
+ var vals []any
vals, err = readCorpusData(data, types)
if err != nil {
errs = append(errs, fmt.Errorf("%q: %v", filename, err))
@@ -982,7 +982,7 @@ func ReadCorpus(dir string, types []reflect.Type) ([]CorpusEntry, error) {
return corpus, nil
}
-func readCorpusData(data []byte, types []reflect.Type) ([]interface{}, error) {
+func readCorpusData(data []byte, types []reflect.Type) ([]any, error) {
vals, err := unmarshalCorpusFile(data)
if err != nil {
return nil, fmt.Errorf("unmarshal: %v", err)
@@ -995,7 +995,7 @@ func readCorpusData(data []byte, types []reflect.Type) ([]interface{}, error) {
// CheckCorpus verifies that the types in vals match the expected types
// provided.
-func CheckCorpus(vals []interface{}, types []reflect.Type) error {
+func CheckCorpus(vals []any, types []reflect.Type) error {
if len(vals) != len(types) {
return fmt.Errorf("wrong number of values in corpus entry: %d, want %d", len(vals), len(types))
}
@@ -1032,7 +1032,7 @@ func testName(path string) string {
return filepath.Base(path)
}
-func zeroValue(t reflect.Type) interface{} {
+func zeroValue(t reflect.Type) any {
for _, v := range zeroVals {
if reflect.TypeOf(v) == t {
return v
@@ -1041,7 +1041,7 @@ func zeroValue(t reflect.Type) interface{} {
panic(fmt.Sprintf("unsupported type: %v", t))
}
-var zeroVals []interface{} = []interface{}{
+var zeroVals []any = []any{
[]byte(""),
string(""),
false,
diff --git a/src/internal/fuzz/minimize_test.go b/src/internal/fuzz/minimize_test.go
index f9041d1d34..6e5f3184b4 100644
--- a/src/internal/fuzz/minimize_test.go
+++ b/src/internal/fuzz/minimize_test.go
@@ -22,8 +22,8 @@ func TestMinimizeInput(t *testing.T) {
type testcase struct {
name string
fn func(CorpusEntry) error
- input []interface{}
- expected []interface{}
+ input []any
+ expected []any
}
cases := []testcase{
{
@@ -41,8 +41,8 @@ func TestMinimizeInput(t *testing.T) {
}
return nil
},
- input: []interface{}{[]byte{0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- expected: []interface{}{[]byte{1, 1, 1}},
+ input: []any{[]byte{0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+ expected: []any{[]byte{1, 1, 1}},
},
{
name: "single_bytes",
@@ -56,8 +56,8 @@ func TestMinimizeInput(t *testing.T) {
}
return fmt.Errorf("bad %v", e.Values[0])
},
- input: []interface{}{[]byte{1, 2, 3, 4, 5}},
- expected: []interface{}{[]byte("00")},
+ input: []any{[]byte{1, 2, 3, 4, 5}},
+ expected: []any{[]byte("00")},
},
{
name: "set_of_bytes",
@@ -71,8 +71,8 @@ func TestMinimizeInput(t *testing.T) {
}
return nil
},
- input: []interface{}{[]byte{0, 1, 2, 3, 4, 5}},
- expected: []interface{}{[]byte{0, 4, 5}},
+ input: []any{[]byte{0, 1, 2, 3, 4, 5}},
+ expected: []any{[]byte{0, 4, 5}},
},
{
name: "non_ascii_bytes",
@@ -83,8 +83,8 @@ func TestMinimizeInput(t *testing.T) {
}
return nil
},
- input: []interface{}{[]byte("ท")}, // ท is 3 bytes
- expected: []interface{}{[]byte("000")},
+ input: []any{[]byte("ท")}, // ท is 3 bytes
+ expected: []any{[]byte("000")},
},
{
name: "ones_string",
@@ -101,8 +101,8 @@ func TestMinimizeInput(t *testing.T) {
}
return nil
},
- input: []interface{}{"001010001000000000000000000"},
- expected: []interface{}{"111"},
+ input: []any{"001010001000000000000000000"},
+ expected: []any{"111"},
},
{
name: "string_length",
@@ -113,8 +113,8 @@ func TestMinimizeInput(t *testing.T) {
}
return nil
},
- input: []interface{}{"zzzzz"},
- expected: []interface{}{"00000"},
+ input: []any{"zzzzz"},
+ expected: []any{"00000"},
},
{
name: "string_with_letter",
@@ -126,8 +126,8 @@ func TestMinimizeInput(t *testing.T) {
}
return nil
},
- input: []interface{}{"ZZZZZ"},
- expected: []interface{}{"A"},
+ input: []any{"ZZZZZ"},
+ expected: []any{"A"},
},
}
@@ -167,7 +167,7 @@ func TestMinimizeFlaky(t *testing.T) {
return time.Second, errors.New("ohno")
}}
mem := &sharedMem{region: make([]byte, 100)} // big enough to hold value and header
- vals := []interface{}{[]byte(nil)}
+ vals := []any{[]byte(nil)}
args := minimizeArgs{KeepCoverage: make([]byte, len(coverageSnapshot))}
success, err := ws.minimizeInput(context.Background(), vals, mem, args)
if success {
diff --git a/src/internal/fuzz/mutator.go b/src/internal/fuzz/mutator.go
index a3161c04ea..e26ae5a583 100644
--- a/src/internal/fuzz/mutator.go
+++ b/src/internal/fuzz/mutator.go
@@ -53,7 +53,7 @@ func min(a, b int) int {
}
// mutate performs several mutations on the provided values.
-func (m *mutator) mutate(vals []interface{}, maxBytes int) {
+func (m *mutator) mutate(vals []any, maxBytes int) {
// TODO(katiehockman): pull some of these functions into helper methods and
// test that each case is working as expected.
// TODO(katiehockman): perform more types of mutations for []byte.
diff --git a/src/internal/fuzz/mutator_test.go b/src/internal/fuzz/mutator_test.go
index d8015ce213..cea7e2e3be 100644
--- a/src/internal/fuzz/mutator_test.go
+++ b/src/internal/fuzz/mutator_test.go
@@ -34,7 +34,7 @@ func BenchmarkMutatorBytes(b *testing.B) {
// resize buffer to the correct shape and reset the PCG
buf = buf[0:size]
m.r = newPcgRand()
- m.mutate([]interface{}{buf}, workerSharedMemSize)
+ m.mutate([]any{buf}, workerSharedMemSize)
}
})
}
@@ -62,7 +62,7 @@ func BenchmarkMutatorString(b *testing.B) {
// resize buffer to the correct shape and reset the PCG
buf = buf[0:size]
m.r = newPcgRand()
- m.mutate([]interface{}{string(buf)}, workerSharedMemSize)
+ m.mutate([]any{string(buf)}, workerSharedMemSize)
}
})
}
@@ -74,7 +74,7 @@ func BenchmarkMutatorAllBasicTypes(b *testing.B) {
os.Setenv("GODEBUG", fmt.Sprintf("%s,fuzzseed=123", origEnv))
m := newMutator()
- types := []interface{}{
+ types := []any{
[]byte(""),
string(""),
false,
@@ -95,14 +95,14 @@ func BenchmarkMutatorAllBasicTypes(b *testing.B) {
b.Run(fmt.Sprintf("%T", t), func(b *testing.B) {
for i := 0; i < b.N; i++ {
m.r = newPcgRand()
- m.mutate([]interface{}{t}, workerSharedMemSize)
+ m.mutate([]any{t}, workerSharedMemSize)
}
})
}
}
func TestStringImmutability(t *testing.T) {
- v := []interface{}{"hello"}
+ v := []any{"hello"}
m := newMutator()
m.mutate(v, 1024)
original := v[0].(string)
diff --git a/src/internal/fuzz/queue.go b/src/internal/fuzz/queue.go
index cf67a28ba7..42a8379541 100644
--- a/src/internal/fuzz/queue.go
+++ b/src/internal/fuzz/queue.go
@@ -16,7 +16,7 @@ type queue struct {
// The queue is empty when begin = end.
// The queue is full (until grow is called) when end = begin + N - 1 (mod N)
// where N = cap(elems).
- elems []interface{}
+ elems []any
head, len int
}
@@ -30,7 +30,7 @@ func (q *queue) grow() {
if newCap == 0 {
newCap = 8
}
- newElems := make([]interface{}, newCap)
+ newElems := make([]any, newCap)
oldLen := q.len
for i := 0; i < oldLen; i++ {
newElems[i] = q.elems[(q.head+i)%oldCap]
@@ -39,7 +39,7 @@ func (q *queue) grow() {
q.head = 0
}
-func (q *queue) enqueue(e interface{}) {
+func (q *queue) enqueue(e any) {
if q.len+1 > q.cap() {
q.grow()
}
@@ -48,7 +48,7 @@ func (q *queue) enqueue(e interface{}) {
q.len++
}
-func (q *queue) dequeue() (interface{}, bool) {
+func (q *queue) dequeue() (any, bool) {
if q.len == 0 {
return nil, false
}
@@ -59,7 +59,7 @@ func (q *queue) dequeue() (interface{}, bool) {
return e, true
}
-func (q *queue) peek() (interface{}, bool) {
+func (q *queue) peek() (any, bool) {
if q.len == 0 {
return nil, false
}
diff --git a/src/internal/fuzz/worker.go b/src/internal/fuzz/worker.go
index c39804cad1..c2d553240c 100644
--- a/src/internal/fuzz/worker.go
+++ b/src/internal/fuzz/worker.go
@@ -654,7 +654,7 @@ func (ws *workerServer) serve(ctx context.Context) error {
}
}
- var resp interface{}
+ var resp any
switch {
case c.Fuzz != nil:
resp = ws.fuzz(ctx, *c.Fuzz)
@@ -726,7 +726,7 @@ func (ws *workerServer) fuzz(ctx context.Context, args fuzzArgs) (resp fuzzRespo
resp.InternalErr = err.Error()
return resp
}
- vals := make([]interface{}, len(originalVals))
+ vals := make([]any, len(originalVals))
copy(vals, originalVals)
shouldStop := func() bool {
@@ -827,7 +827,7 @@ func (ws *workerServer) minimize(ctx context.Context, args minimizeArgs) (resp m
// coverage, in fuzzFn. It uses the context to determine how long to run,
// stopping once closed. It returns a bool indicating whether minimization was
// successful and an error if one was found.
-func (ws *workerServer) minimizeInput(ctx context.Context, vals []interface{}, mem *sharedMem, args minimizeArgs) (success bool, retErr error) {
+func (ws *workerServer) minimizeInput(ctx context.Context, vals []any, mem *sharedMem, args minimizeArgs) (success bool, retErr error) {
keepCoverage := args.KeepCoverage
memBytes := mem.valueRef()
bPtr := &memBytes
@@ -900,7 +900,7 @@ func (ws *workerServer) minimizeInput(ctx context.Context, vals []interface{}, m
return true, retErr
}
-func writeToMem(vals []interface{}, mem *sharedMem) {
+func writeToMem(vals []any, mem *sharedMem) {
b := marshalCorpusFile(vals...)
mem.setValue(b)
}
@@ -1127,7 +1127,7 @@ func (wc *workerClient) ping(ctx context.Context) error {
// callLocked sends an RPC from the coordinator to the worker process and waits
// for the response. The callLocked may be cancelled with ctx.
-func (wc *workerClient) callLocked(ctx context.Context, c call, resp interface{}) (err error) {
+func (wc *workerClient) callLocked(ctx context.Context, c call, resp any) (err error) {
enc := json.NewEncoder(wc.fuzzIn)
dec := json.NewDecoder(&contextReader{ctx: ctx, r: wc.fuzzOut})
if err := enc.Encode(c); err != nil {
diff --git a/src/internal/fuzz/worker_test.go b/src/internal/fuzz/worker_test.go
index e2ecf0a9c3..d0b21da783 100644
--- a/src/internal/fuzz/worker_test.go
+++ b/src/internal/fuzz/worker_test.go
@@ -53,7 +53,7 @@ func BenchmarkWorkerFuzzOverhead(b *testing.B) {
}
}()
- initialVal := []interface{}{make([]byte, 32)}
+ initialVal := []any{make([]byte, 32)}
encodedVals := marshalCorpusFile(initialVal...)
mem.setValue(encodedVals)
@@ -92,7 +92,7 @@ func BenchmarkWorkerFuzz(b *testing.B) {
}
b.SetParallelism(1)
w := newWorkerForTest(b)
- entry := CorpusEntry{Values: []interface{}{[]byte(nil)}}
+ entry := CorpusEntry{Values: []any{[]byte(nil)}}
entry.Data = marshalCorpusFile(entry.Values...)
for i := int64(0); i < int64(b.N); {
args := fuzzArgs{
@@ -183,7 +183,7 @@ func BenchmarkWorkerMinimize(b *testing.B) {
ctx := context.Background()
for sz := 1; sz <= len(bytes); sz <<= 1 {
sz := sz
- input := []interface{}{bytes[:sz]}
+ input := []any{bytes[:sz]}
encodedVals := marshalCorpusFile(input...)
mem = <-ws.memMu
mem.setValue(encodedVals)
diff --git a/src/internal/intern/intern.go b/src/internal/intern/intern.go
index 666caa6d2f..75641106ab 100644
--- a/src/internal/intern/intern.go
+++ b/src/internal/intern/intern.go
@@ -21,7 +21,7 @@ import (
// See func Get for how Value pointers may be used.
type Value struct {
_ [0]func() // prevent people from accidentally using value type as comparable
- cmpVal interface{}
+ cmpVal any
// resurrected is guarded by mu (for all instances of Value).
// It is set true whenever v is synthesized from a uintptr.
resurrected bool
@@ -29,21 +29,21 @@ type Value struct {
// Get returns the comparable value passed to the Get func
// that returned v.
-func (v *Value) Get() interface{} { return v.cmpVal }
+func (v *Value) Get() any { return v.cmpVal }
// key is a key in our global value map.
// It contains type-specialized fields to avoid allocations
// when converting common types to empty interfaces.
type key struct {
s string
- cmpVal interface{}
+ cmpVal any
// isString reports whether key contains a string.
// Without it, the zero value of key is ambiguous.
isString bool
}
// keyFor returns a key to use with cmpVal.
-func keyFor(cmpVal interface{}) key {
+func keyFor(cmpVal any) key {
if s, ok := cmpVal.(string); ok {
return key{s: s, isString: true}
}
@@ -79,7 +79,7 @@ func safeMap() map[key]*Value {
//
// The returned pointer will be the same for Get(v) and Get(v2)
// if and only if v == v2, and can be used as a map key.
-func Get(cmpVal interface{}) *Value {
+func Get(cmpVal any) *Value {
return get(keyFor(cmpVal))
}
diff --git a/src/internal/lazytemplate/lazytemplate.go b/src/internal/lazytemplate/lazytemplate.go
index c83eaeaf3e..8eeed5a527 100644
--- a/src/internal/lazytemplate/lazytemplate.go
+++ b/src/internal/lazytemplate/lazytemplate.go
@@ -33,7 +33,7 @@ func (r *Template) build() {
r.name, r.text = "", ""
}
-func (r *Template) Execute(w io.Writer, data interface{}) error {
+func (r *Template) Execute(w io.Writer, data any) error {
return r.tp().Execute(w, data)
}
diff --git a/src/internal/nettrace/nettrace.go b/src/internal/nettrace/nettrace.go
index de3254df58..94f38a71ee 100644
--- a/src/internal/nettrace/nettrace.go
+++ b/src/internal/nettrace/nettrace.go
@@ -30,7 +30,7 @@ type Trace struct {
// The coalesced parameter is whether singleflight de-dupped
// the call. The addrs are of type net.IPAddr but can't
// actually be for circular dependency reasons.
- DNSDone func(netIPs []interface{}, coalesced bool, err error)
+ DNSDone func(netIPs []any, coalesced bool, err error)
// ConnectStart is called before a Dial, excluding Dials made
// during DNS lookups. In the case of DualStack (Happy Eyeballs)
diff --git a/src/internal/poll/splice_linux.go b/src/internal/poll/splice_linux.go
index 2d87c3d023..43eec04a71 100644
--- a/src/internal/poll/splice_linux.go
+++ b/src/internal/poll/splice_linux.go
@@ -173,7 +173,7 @@ type splicePipe struct {
// a finalizer for each pipe to close its file descriptors before the actual GC.
var splicePipePool = sync.Pool{New: newPoolPipe}
-func newPoolPipe() interface{} {
+func newPoolPipe() any {
// Discard the error which occurred during the creation of pipe buffer,
// redirecting the data transmission to the conventional way utilizing read() + write() as a fallback.
p := newPipe()
diff --git a/src/internal/poll/splice_linux_test.go b/src/internal/poll/splice_linux_test.go
index 8c4363886e..29bcaab414 100644
--- a/src/internal/poll/splice_linux_test.go
+++ b/src/internal/poll/splice_linux_test.go
@@ -73,7 +73,7 @@ func TestSplicePipePool(t *testing.T) {
// Detect whether all pipes are closed properly.
var leakedFDs []int
- pendingFDs.Range(func(k, v interface{}) bool {
+ pendingFDs.Range(func(k, v any) bool {
leakedFDs = append(leakedFDs, k.(int))
return true
})
diff --git a/src/internal/reflectlite/all_test.go b/src/internal/reflectlite/all_test.go
index e15f364fcd..ea750831ef 100644
--- a/src/internal/reflectlite/all_test.go
+++ b/src/internal/reflectlite/all_test.go
@@ -32,7 +32,7 @@ type T struct {
}
type pair struct {
- i interface{}
+ i any
s string
}
@@ -421,7 +421,7 @@ func TestAll(t *testing.T) {
func TestInterfaceValue(t *testing.T) {
var inter struct {
- E interface{}
+ E any
}
inter.E = 123.456
v1 := ValueOf(&inter)
@@ -437,7 +437,7 @@ func TestInterfaceValue(t *testing.T) {
}
func TestFunctionValue(t *testing.T) {
- var x interface{} = func() {}
+ var x any = func() {}
v := ValueOf(x)
if fmt.Sprint(ToInterface(v)) != fmt.Sprint(x) {
t.Fatalf("TestFunction returned wrong pointer")
@@ -496,7 +496,7 @@ type Basic struct {
type NotBasic Basic
type DeepEqualTest struct {
- a, b interface{}
+ a, b any
eq bool
}
@@ -510,7 +510,7 @@ var (
type self struct{}
type Loop *Loop
-type Loopy interface{}
+type Loopy any
var loop1, loop2 Loop
var loopy1, loopy2 Loopy
@@ -578,7 +578,7 @@ var typeOfTests = []DeepEqualTest{
{int32(1), int64(1), false},
{0.5, "hello", false},
{[]int{1, 2, 3}, [3]int{1, 2, 3}, false},
- {&[3]interface{}{1, 2, 4}, &[3]interface{}{1, 2, "s"}, false},
+ {&[3]any{1, 2, 4}, &[3]any{1, 2, "s"}, false},
{Basic{1, 0.5}, NotBasic{1, 0.5}, false},
{map[uint]string{1: "one", 2: "two"}, map[int]string{2: "two", 1: "one"}, false},
@@ -606,14 +606,14 @@ func TestTypeOf(t *testing.T) {
}
}
-func Nil(a interface{}, t *testing.T) {
+func Nil(a any, t *testing.T) {
n := Field(ValueOf(a), 0)
if !n.IsNil() {
t.Errorf("%v should be nil", a)
}
}
-func NotNil(a interface{}, t *testing.T) {
+func NotNil(a any, t *testing.T) {
n := Field(ValueOf(a), 0)
if n.IsNil() {
t.Errorf("value of type %v should not be nil", TypeString(ValueOf(a).Type()))
@@ -623,9 +623,9 @@ func NotNil(a interface{}, t *testing.T) {
func TestIsNil(t *testing.T) {
// These implement IsNil.
// Wrap in extra struct to hide interface type.
- doNil := []interface{}{
+ doNil := []any{
struct{ x *int }{},
- struct{ x interface{} }{},
+ struct{ x any }{},
struct{ x map[string]int }{},
struct{ x func() bool }{},
struct{ x chan int }{},
@@ -668,7 +668,7 @@ func TestIsNil(t *testing.T) {
NotNil(mi, t)
var ii struct {
- x interface{}
+ x any
}
Nil(ii, t)
ii.x = 2
@@ -770,7 +770,7 @@ func TestImportPath(t *testing.T) {
{TypeOf([]byte(nil)), ""},
{TypeOf([]rune(nil)), ""},
{TypeOf(string("")), ""},
- {TypeOf((*interface{})(nil)).Elem(), ""},
+ {TypeOf((*any)(nil)).Elem(), ""},
{TypeOf((*byte)(nil)), ""},
{TypeOf((*rune)(nil)), ""},
{TypeOf((*int64)(nil)), ""},
@@ -805,7 +805,7 @@ func noAlloc(t *testing.T, n int, f func(int)) {
func TestAllocations(t *testing.T) {
noAlloc(t, 100, func(j int) {
- var i interface{}
+ var i any
var v Value
// We can uncomment this when compiler escape analysis
@@ -939,7 +939,7 @@ func TestBigZero(t *testing.T) {
func TestInvalid(t *testing.T) {
// Used to have inconsistency between IsValid() and Kind() != Invalid.
- type T struct{ v interface{} }
+ type T struct{ v any }
v := Field(ValueOf(T{}), 0)
if v.IsValid() != true || v.Kind() != Interface {
@@ -954,7 +954,7 @@ func TestInvalid(t *testing.T) {
type TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678 int
type nameTest struct {
- v interface{}
+ v any
want string
}
@@ -966,7 +966,7 @@ var nameTests = []nameTest{
{(*func() D1)(nil), ""},
{(*<-chan D1)(nil), ""},
{(*chan<- D1)(nil), ""},
- {(*interface{})(nil), ""},
+ {(*any)(nil), ""},
{(*interface {
F()
})(nil), ""},
diff --git a/src/internal/reflectlite/export_test.go b/src/internal/reflectlite/export_test.go
index 354ea9dbd0..adae229e92 100644
--- a/src/internal/reflectlite/export_test.go
+++ b/src/internal/reflectlite/export_test.go
@@ -81,7 +81,7 @@ func Zero(typ Type) Value {
// var i interface{} = (v's underlying value)
// It panics if the Value was obtained by accessing
// unexported struct fields.
-func ToInterface(v Value) (i interface{}) {
+func ToInterface(v Value) (i any) {
return valueInterface(v)
}
diff --git a/src/internal/reflectlite/set_test.go b/src/internal/reflectlite/set_test.go
index a610499d08..ca7ea9b0bc 100644
--- a/src/internal/reflectlite/set_test.go
+++ b/src/internal/reflectlite/set_test.go
@@ -26,8 +26,8 @@ func TestImplicitSetConversion(t *testing.T) {
}
var implementsTests = []struct {
- x interface{}
- t interface{}
+ x any
+ t any
b bool
}{
{new(*bytes.Buffer), new(io.Reader), true},
@@ -73,8 +73,8 @@ func TestImplements(t *testing.T) {
}
var assignableTests = []struct {
- x interface{}
- t interface{}
+ x any
+ t any
b bool
}{
{new(chan int), new(<-chan int), true},
@@ -82,13 +82,13 @@ var assignableTests = []struct {
{new(*int), new(IntPtr), true},
{new(IntPtr), new(*int), true},
{new(IntPtr), new(IntPtr1), false},
- {new(Ch), new(<-chan interface{}), true},
+ {new(Ch), new(<-chan any), true},
// test runs implementsTests too
}
type IntPtr *int
type IntPtr1 *int
-type Ch <-chan interface{}
+type Ch <-chan any
func TestAssignableTo(t *testing.T) {
for i, tt := range append(assignableTests, implementsTests...) {
diff --git a/src/internal/reflectlite/swapper.go b/src/internal/reflectlite/swapper.go
index ac081d49bb..fc402bb38a 100644
--- a/src/internal/reflectlite/swapper.go
+++ b/src/internal/reflectlite/swapper.go
@@ -14,7 +14,7 @@ import (
// slice.
//
// Swapper panics if the provided interface is not a slice.
-func Swapper(slice interface{}) func(i, j int) {
+func Swapper(slice any) func(i, j int) {
v := ValueOf(slice)
if v.Kind() != Slice {
panic(&ValueError{Method: "Swapper", Kind: v.Kind()})
diff --git a/src/internal/reflectlite/type.go b/src/internal/reflectlite/type.go
index fdf1584a27..8f649600d2 100644
--- a/src/internal/reflectlite/type.go
+++ b/src/internal/reflectlite/type.go
@@ -707,7 +707,7 @@ func (t *interfaceType) NumMethod() int { return len(t.methods) }
// TypeOf returns the reflection Type that represents the dynamic type of i.
// If i is a nil interface value, TypeOf returns nil.
-func TypeOf(i interface{}) Type {
+func TypeOf(i any) Type {
eface := *(*emptyInterface)(unsafe.Pointer(&i))
return toType(eface.typ)
}
diff --git a/src/internal/reflectlite/value.go b/src/internal/reflectlite/value.go
index 0734069255..966230f581 100644
--- a/src/internal/reflectlite/value.go
+++ b/src/internal/reflectlite/value.go
@@ -99,9 +99,9 @@ func (v Value) pointer() unsafe.Pointer {
}
// packEface converts v to the empty interface.
-func packEface(v Value) interface{} {
+func packEface(v Value) any {
t := v.typ
- var i interface{}
+ var i any
e := (*emptyInterface)(unsafe.Pointer(&i))
// First, fill in the data portion of the interface.
switch {
@@ -136,7 +136,7 @@ func packEface(v Value) interface{} {
}
// unpackEface converts the empty interface i to a Value.
-func unpackEface(i interface{}) Value {
+func unpackEface(i any) Value {
e := (*emptyInterface)(unsafe.Pointer(&i))
// NOTE: don't read e.word until we know whether it is really a pointer or not.
t := e.typ
@@ -226,11 +226,11 @@ func (v Value) Elem() Value {
k := v.kind()
switch k {
case Interface:
- var eface interface{}
+ var eface any
if v.typ.NumMethod() == 0 {
- eface = *(*interface{})(v.ptr)
+ eface = *(*any)(v.ptr)
} else {
- eface = (interface{})(*(*interface {
+ eface = (any)(*(*interface {
M()
})(v.ptr))
}
@@ -257,7 +257,7 @@ func (v Value) Elem() Value {
panic(&ValueError{"reflectlite.Value.Elem", v.kind()})
}
-func valueInterface(v Value) interface{} {
+func valueInterface(v Value) any {
if v.flag == 0 {
panic(&ValueError{"reflectlite.Value.Interface", 0})
}
@@ -267,7 +267,7 @@ func valueInterface(v Value) interface{} {
// Empty interface has one layout, all interfaces with
// methods have a second layout.
if v.numMethod() == 0 {
- return *(*interface{})(v.ptr)
+ return *(*any)(v.ptr)
}
return *(*interface {
M()
@@ -391,7 +391,7 @@ func unsafe_New(*rtype) unsafe.Pointer
// ValueOf returns a new Value initialized to the concrete value
// stored in the interface i. ValueOf(nil) returns the zero Value.
-func ValueOf(i interface{}) Value {
+func ValueOf(i any) Value {
if i == nil {
return Value{}
}
@@ -433,7 +433,7 @@ func (v Value) assignTo(context string, dst *rtype, target unsafe.Pointer) Value
}
x := valueInterface(v)
if dst.NumMethod() == 0 {
- *(*interface{})(target) = x
+ *(*any)(target) = x
} else {
ifaceE2I(dst, x, target)
}
@@ -455,7 +455,7 @@ func arrayAt(p unsafe.Pointer, i int, eltSize uintptr, whySafe string) unsafe.Po
return add(p, uintptr(i)*eltSize, "i < len")
}
-func ifaceE2I(t *rtype, src interface{}, dst unsafe.Pointer)
+func ifaceE2I(t *rtype, src any, dst unsafe.Pointer)
// typedmemmove copies a value of type t to dst from src.
//go:noescape
@@ -464,7 +464,7 @@ func typedmemmove(t *rtype, dst, src unsafe.Pointer)
// Dummy annotation marking that the value x escapes,
// for use in cases where the reflect code is so clever that
// the compiler cannot follow.
-func escapes(x interface{}) {
+func escapes(x any) {
if dummy.b {
dummy.x = x
}
@@ -472,5 +472,5 @@ func escapes(x interface{}) {
var dummy struct {
b bool
- x interface{}
+ x any
}
diff --git a/src/internal/singleflight/singleflight.go b/src/internal/singleflight/singleflight.go
index b2d82e26c2..07b3f40ec0 100644
--- a/src/internal/singleflight/singleflight.go
+++ b/src/internal/singleflight/singleflight.go
@@ -14,7 +14,7 @@ type call struct {
// These fields are written once before the WaitGroup is done
// and are only read after the WaitGroup is done.
- val interface{}
+ val any
err error
// These fields are read and written with the singleflight
@@ -34,7 +34,7 @@ type Group struct {
// Result holds the results of Do, so they can be passed
// on a channel.
type Result struct {
- Val interface{}
+ Val any
Err error
Shared bool
}
@@ -44,7 +44,7 @@ type Result struct {
// time. If a duplicate comes in, the duplicate caller waits for the
// original to complete and receives the same results.
// The return value shared indicates whether v was given to multiple callers.
-func (g *Group) Do(key string, fn func() (interface{}, error)) (v interface{}, err error, shared bool) {
+func (g *Group) Do(key string, fn func() (any, error)) (v any, err error, shared bool) {
g.mu.Lock()
if g.m == nil {
g.m = make(map[string]*call)
@@ -68,7 +68,7 @@ func (g *Group) Do(key string, fn func() (interface{}, error)) (v interface{}, e
// results when they are ready. The second result is true if the function
// will eventually be called, false if it will not (because there is
// a pending request with this key).
-func (g *Group) DoChan(key string, fn func() (interface{}, error)) (<-chan Result, bool) {
+func (g *Group) DoChan(key string, fn func() (any, error)) (<-chan Result, bool) {
ch := make(chan Result, 1)
g.mu.Lock()
if g.m == nil {
@@ -91,7 +91,7 @@ func (g *Group) DoChan(key string, fn func() (interface{}, error)) (<-chan Resul
}
// doCall handles the single call for a key.
-func (g *Group) doCall(c *call, key string, fn func() (interface{}, error)) {
+func (g *Group) doCall(c *call, key string, fn func() (any, error)) {
c.val, c.err = fn()
c.wg.Done()
diff --git a/src/internal/singleflight/singleflight_test.go b/src/internal/singleflight/singleflight_test.go
index 6404a1775a..c2310375f7 100644
--- a/src/internal/singleflight/singleflight_test.go
+++ b/src/internal/singleflight/singleflight_test.go
@@ -15,7 +15,7 @@ import (
func TestDo(t *testing.T) {
var g Group
- v, err, _ := g.Do("key", func() (interface{}, error) {
+ v, err, _ := g.Do("key", func() (any, error) {
return "bar", nil
})
if got, want := fmt.Sprintf("%v (%T)", v, v), "bar (string)"; got != want {
@@ -29,7 +29,7 @@ func TestDo(t *testing.T) {
func TestDoErr(t *testing.T) {
var g Group
someErr := errors.New("some error")
- v, err, _ := g.Do("key", func() (interface{}, error) {
+ v, err, _ := g.Do("key", func() (any, error) {
return nil, someErr
})
if err != someErr {
@@ -45,7 +45,7 @@ func TestDoDupSuppress(t *testing.T) {
var wg1, wg2 sync.WaitGroup
c := make(chan string, 1)
var calls int32
- fn := func() (interface{}, error) {
+ fn := func() (any, error) {
if atomic.AddInt32(&calls, 1) == 1 {
// First invocation.
wg1.Done()
diff --git a/src/internal/syscall/windows/registry/registry_test.go b/src/internal/syscall/windows/registry/registry_test.go
index 134b5450fc..278b0b4911 100644
--- a/src/internal/syscall/windows/registry/registry_test.go
+++ b/src/internal/syscall/windows/registry/registry_test.go
@@ -118,7 +118,7 @@ func equalStringSlice(a, b []string) bool {
type ValueTest struct {
Type uint32
Name string
- Value interface{}
+ Value any
WillFail bool
}
diff --git a/src/internal/trace/gc.go b/src/internal/trace/gc.go
index cc19fdf891..c1bc862340 100644
--- a/src/internal/trace/gc.go
+++ b/src/internal/trace/gc.go
@@ -352,11 +352,11 @@ func (h bandUtilHeap) Swap(i, j int) {
h[i], h[j] = h[j], h[i]
}
-func (h *bandUtilHeap) Push(x interface{}) {
+func (h *bandUtilHeap) Push(x any) {
*h = append(*h, x.(bandUtil))
}
-func (h *bandUtilHeap) Pop() interface{} {
+func (h *bandUtilHeap) Pop() any {
x := (*h)[len(*h)-1]
*h = (*h)[:len(*h)-1]
return x
@@ -386,11 +386,11 @@ func (h utilHeap) Swap(i, j int) {
h[i], h[j] = h[j], h[i]
}
-func (h *utilHeap) Push(x interface{}) {
+func (h *utilHeap) Push(x any) {
*h = append(*h, x.(UtilWindow))
}
-func (h *utilHeap) Pop() interface{} {
+func (h *utilHeap) Pop() any {
x := (*h)[len(*h)-1]
*h = (*h)[:len(*h)-1]
return x
diff --git a/src/internal/unsafeheader/unsafeheader_test.go b/src/internal/unsafeheader/unsafeheader_test.go
index 6fb7cca888..f3d1a9bb68 100644
--- a/src/internal/unsafeheader/unsafeheader_test.go
+++ b/src/internal/unsafeheader/unsafeheader_test.go
@@ -25,7 +25,7 @@ func TestTypeMatchesReflectType(t *testing.T) {
})
}
-func testHeaderMatchesReflect(t *testing.T, header, reflectHeader interface{}) {
+func testHeaderMatchesReflect(t *testing.T, header, reflectHeader any) {
h := reflect.TypeOf(header)
rh := reflect.TypeOf(reflectHeader)