Skip to content

Commit a363d11

Browse files
findleyrgopherbot
authored andcommitted
go/types/typeutil: replace interface{} with any (cleanup)
Change-Id: If5b8faffbf4a60338bab4eb3c5fbcc6a3c3c3952 Reviewed-on: https://go-review.googlesource.com/c/tools/+/581116 Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Robert Findley <[email protected]>
1 parent e8c9d81 commit a363d11

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

go/types/typeutil/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func g(rune) (uint8, bool)
5252

5353
// Format, sort, and print the map entries.
5454
var lines []string
55-
namesByType.Iterate(func(T types.Type, names interface{}) {
55+
namesByType.Iterate(func(T types.Type, names any) {
5656
lines = append(lines, fmt.Sprintf("%s %s", names, T))
5757
})
5858
sort.Strings(lines)

go/types/typeutil/map.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// license that can be found in the LICENSE file.
44

55
// Package typeutil defines various utilities for types, such as Map,
6-
// a mapping from types.Type to interface{} values.
6+
// a mapping from types.Type to any values.
77
package typeutil // import "golang.org/x/tools/go/types/typeutil"
88

99
import (
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
// Map is a hash-table-based mapping from types (types.Type) to
20-
// arbitrary interface{} values. The concrete types that implement
20+
// arbitrary any values. The concrete types that implement
2121
// the Type interface are pointers. Since they are not canonicalized,
2222
// == cannot be used to check for equivalence, and thus we cannot
2323
// simply use a Go map.
@@ -34,7 +34,7 @@ type Map struct {
3434
// entry is an entry (key/value association) in a hash bucket.
3535
type entry struct {
3636
key types.Type
37-
value interface{}
37+
value any
3838
}
3939

4040
// SetHasher sets the hasher used by Map.
@@ -82,7 +82,7 @@ func (m *Map) Delete(key types.Type) bool {
8282

8383
// At returns the map entry for the given key.
8484
// The result is nil if the entry is not present.
85-
func (m *Map) At(key types.Type) interface{} {
85+
func (m *Map) At(key types.Type) any {
8686
if m != nil && m.table != nil {
8787
for _, e := range m.table[m.hasher.Hash(key)] {
8888
if e.key != nil && types.Identical(key, e.key) {
@@ -95,7 +95,7 @@ func (m *Map) At(key types.Type) interface{} {
9595

9696
// Set sets the map entry for key to val,
9797
// and returns the previous entry, if any.
98-
func (m *Map) Set(key types.Type, value interface{}) (prev interface{}) {
98+
func (m *Map) Set(key types.Type, value any) (prev any) {
9999
if m.table != nil {
100100
hash := m.hasher.Hash(key)
101101
bucket := m.table[hash]
@@ -142,7 +142,7 @@ func (m *Map) Len() int {
142142
// f will not be invoked for it, but if f inserts a map entry that
143143
// Iterate has not yet reached, whether or not f will be invoked for
144144
// it is unspecified.
145-
func (m *Map) Iterate(f func(key types.Type, value interface{})) {
145+
func (m *Map) Iterate(f func(key types.Type, value any)) {
146146
if m != nil {
147147
for _, bucket := range m.table {
148148
for _, e := range bucket {
@@ -158,7 +158,7 @@ func (m *Map) Iterate(f func(key types.Type, value interface{})) {
158158
// The order is unspecified.
159159
func (m *Map) Keys() []types.Type {
160160
keys := make([]types.Type, 0, m.Len())
161-
m.Iterate(func(key types.Type, _ interface{}) {
161+
m.Iterate(func(key types.Type, _ any) {
162162
keys = append(keys, key)
163163
})
164164
return keys
@@ -171,7 +171,7 @@ func (m *Map) toString(values bool) string {
171171
var buf bytes.Buffer
172172
fmt.Fprint(&buf, "{")
173173
sep := ""
174-
m.Iterate(func(key types.Type, value interface{}) {
174+
m.Iterate(func(key types.Type, value any) {
175175
fmt.Fprint(&buf, sep)
176176
sep = ", "
177177
fmt.Fprint(&buf, key)
@@ -209,7 +209,7 @@ type Hasher struct {
209209
memo map[types.Type]uint32
210210

211211
// ptrMap records pointer identity.
212-
ptrMap map[interface{}]uint32
212+
ptrMap map[any]uint32
213213

214214
// sigTParams holds type parameters from the signature being hashed.
215215
// Signatures are considered identical modulo renaming of type parameters, so
@@ -227,7 +227,7 @@ type Hasher struct {
227227
func MakeHasher() Hasher {
228228
return Hasher{
229229
memo: make(map[types.Type]uint32),
230-
ptrMap: make(map[interface{}]uint32),
230+
ptrMap: make(map[any]uint32),
231231
sigTParams: nil,
232232
}
233233
}
@@ -432,7 +432,7 @@ func (h Hasher) hashTypeParam(t *types.TypeParam) uint32 {
432432

433433
// hashPtr hashes the pointer identity of ptr. It uses h.ptrMap to ensure that
434434
// pointers values are not dependent on the GC.
435-
func (h Hasher) hashPtr(ptr interface{}) uint32 {
435+
func (h Hasher) hashPtr(ptr any) uint32 {
436436
if hash, ok := h.ptrMap[ptr]; ok {
437437
return hash
438438
}

go/types/typeutil/map_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestMap(t *testing.T) {
8686
t.Errorf("At(): got %q, want \"*string\"", v)
8787
}
8888
// Iteration over sole entry.
89-
tmap.Iterate(func(key types.Type, value interface{}) {
89+
tmap.Iterate(func(key types.Type, value any) {
9090
if key != tPStr1 {
9191
t.Errorf("Iterate: key: got %s, want %s", key, tPStr1)
9292
}
@@ -136,7 +136,7 @@ func TestMap(t *testing.T) {
136136
t.Errorf("At(): got %q, want \"*string again\"", v)
137137
}
138138
hamming := 1
139-
tmap.Iterate(func(key types.Type, value interface{}) {
139+
tmap.Iterate(func(key types.Type, value any) {
140140
switch {
141141
case I(key, tChanInt1):
142142
hamming *= 2 // ok
@@ -230,7 +230,7 @@ var ME2 = G2[int].M
230230
var ME1Type func(G1[int], G1[int], G2[int])
231231
232232
// Examples from issue #51314
233-
type Constraint[T any] interface{}
233+
type Constraint[T any] any
234234
func Foo[T Constraint[T]]() {}
235235
func Fn[T1 ~*T2, T2 ~*T1](t1 T1, t2 T2) {}
236236

0 commit comments

Comments
 (0)