Skip to content

Commit d8aa09e

Browse files
kevinGCgvisor-bot
authored andcommitted
convert uses of interface{} to any
Done via: find . -name "*.go" | xargs sed -i -E 's/interface\{\}/any/g' PiperOrigin-RevId: 487033228
1 parent c82b700 commit d8aa09e

File tree

220 files changed

+509
-509
lines changed

Some content is hidden

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

220 files changed

+509
-509
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module gvisor.dev/gvisor
22

3-
go 1.17
3+
go 1.18
44

55
require (
66
github.com/BurntSushi/toml v0.3.1

pkg/abi/linux/netfilter_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
func TestSizes(t *testing.T) {
2323
testCases := []struct {
24-
typ interface{}
24+
typ any
2525
defined uintptr
2626
}{
2727
{IPTEntry{}, SizeOfIPTEntry},

pkg/binary/binary.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func AppendUint64(buf []byte, order binary.ByteOrder, num uint64) []byte {
5959
// data must only contain fixed-length signed and unsigned ints, arrays,
6060
// slices, structs and compositions of said types. data may be a pointer,
6161
// but cannot contain pointers.
62-
func Marshal(buf []byte, order binary.ByteOrder, data interface{}) []byte {
62+
func Marshal(buf []byte, order binary.ByteOrder, data any) []byte {
6363
return marshal(buf, order, reflect.Indirect(reflect.ValueOf(data)))
6464
}
6565

@@ -104,7 +104,7 @@ func marshal(buf []byte, order binary.ByteOrder, data reflect.Value) []byte {
104104
// data must be a slice or a pointer and buf must have a length of exactly
105105
// Size(data). data must only contain fixed-length signed and unsigned ints,
106106
// arrays, slices, structs and compositions of said types.
107-
func Unmarshal(buf []byte, order binary.ByteOrder, data interface{}) {
107+
func Unmarshal(buf []byte, order binary.ByteOrder, data any) {
108108
value := reflect.ValueOf(data)
109109
switch value.Kind() {
110110
case reflect.Ptr:
@@ -170,7 +170,7 @@ func unmarshal(buf []byte, order binary.ByteOrder, data reflect.Value) []byte {
170170
// Size calculates the buffer sized needed by Marshal or Unmarshal.
171171
//
172172
// Size only support the types supported by Marshal.
173-
func Size(v interface{}) uintptr {
173+
func Size(v any) uintptr {
174174
return sizeof(reflect.Indirect(reflect.ValueOf(v)))
175175
}
176176

pkg/binary/binary_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ func TestSize(t *testing.T) {
3838
func TestPanic(t *testing.T) {
3939
tests := []struct {
4040
name string
41-
f func([]byte, binary.ByteOrder, interface{})
42-
data interface{}
41+
f func([]byte, binary.ByteOrder, any)
42+
data any
4343
want string
4444
}{
4545
{"Unmarshal int", Unmarshal, 5, "invalid type: int"},
4646
{"Unmarshal []int", Unmarshal, []int{5}, "invalid type: int"},
47-
{"Marshal int", func(_ []byte, bo binary.ByteOrder, d interface{}) { Marshal(nil, bo, d) }, 5, "invalid type: int"},
48-
{"Marshal int[]", func(_ []byte, bo binary.ByteOrder, d interface{}) { Marshal(nil, bo, d) }, []int{5}, "invalid type: int"},
47+
{"Marshal int", func(_ []byte, bo binary.ByteOrder, d any) { Marshal(nil, bo, d) }, 5, "invalid type: int"},
48+
{"Marshal int[]", func(_ []byte, bo binary.ByteOrder, d any) { Marshal(nil, bo, d) }, []int{5}, "invalid type: int"},
4949
{"Unmarshal short buffer", Unmarshal, newInt32(5), "runtime error: index out of range"},
50-
{"Unmarshal long buffer", func(_ []byte, bo binary.ByteOrder, d interface{}) { Unmarshal(make([]byte, 50), bo, d) }, newInt32(5), "buffer too long by 46 bytes"},
51-
{"marshal int", func(_ []byte, bo binary.ByteOrder, d interface{}) { marshal(nil, bo, reflect.ValueOf(d)) }, 5, "invalid type: int"},
52-
{"Size int", func(_ []byte, _ binary.ByteOrder, d interface{}) { Size(d) }, 5, "invalid type: int"},
50+
{"Unmarshal long buffer", func(_ []byte, bo binary.ByteOrder, d any) { Unmarshal(make([]byte, 50), bo, d) }, newInt32(5), "buffer too long by 46 bytes"},
51+
{"marshal int", func(_ []byte, bo binary.ByteOrder, d any) { marshal(nil, bo, reflect.ValueOf(d)) }, 5, "invalid type: int"},
52+
{"Size int", func(_ []byte, _ binary.ByteOrder, d any) { Size(d) }, 5, "invalid type: int"},
5353
}
5454

5555
for _, test := range tests {

pkg/bufferv2/chunk.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var chunkPools [numPools]sync.Pool
5353
func init() {
5454
for i := 0; i < numPools; i++ {
5555
chunkSize := baseChunkSize * (1 << i)
56-
chunkPools[i].New = func() interface{} {
56+
chunkPools[i].New = func() any {
5757
return &chunk{
5858
data: make([]byte, chunkSize),
5959
}

pkg/bufferv2/view.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
const ReadSize = 512
2727

2828
var viewPool = sync.Pool{
29-
New: func() interface{} {
29+
New: func() any {
3030
return &View{}
3131
},
3232
}

pkg/compressio/compressio.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ import (
5858
)
5959

6060
var bufPool = sync.Pool{
61-
New: func() interface{} {
61+
New: func() any {
6262
return bytes.NewBuffer(nil)
6363
},
6464
}
6565

6666
var chunkPool = sync.Pool{
67-
New: func() interface{} {
67+
New: func() any {
6868
return new(chunk)
6969
},
7070
}

pkg/compressio/compressio_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import (
2727
)
2828

2929
type harness interface {
30-
Errorf(format string, v ...interface{})
31-
Fatalf(format string, v ...interface{})
32-
Logf(format string, v ...interface{})
30+
Errorf(format string, v ...any)
31+
Fatalf(format string, v ...any)
32+
Logf(format string, v ...any)
3333
}
3434

3535
func initTest(t harness, size int) []byte {

pkg/context/context.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func Background() Context {
186186

187187
// WithValue returns a copy of parent in which the value associated with key is
188188
// val.
189-
func WithValue(parent Context, key, val interface{}) Context {
189+
func WithValue(parent Context, key, val any) Context {
190190
return &withValue{
191191
Context: parent,
192192
key: key,
@@ -196,12 +196,12 @@ func WithValue(parent Context, key, val interface{}) Context {
196196

197197
type withValue struct {
198198
Context
199-
key interface{}
200-
val interface{}
199+
key any
200+
val any
201201
}
202202

203203
// Value implements Context.Value.
204-
func (ctx *withValue) Value(key interface{}) interface{} {
204+
func (ctx *withValue) Value(key any) any {
205205
if key == ctx.key {
206206
return ctx.val
207207
}

pkg/control/server/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (s *Server) serve() {
124124
}
125125

126126
// Register registers a specific control interface with the server.
127-
func (s *Server) Register(obj interface{}) {
127+
func (s *Server) Register(obj any) {
128128
s.server.Register(obj)
129129
}
130130

pkg/coverage/coverage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func ClearCoverageData() {
113113
}
114114

115115
var coveragePool = sync.Pool{
116-
New: func() interface{} {
116+
New: func() any {
117117
return make([]byte, 0)
118118
},
119119
}

pkg/cpuid/cpuid.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const (
4242

4343
// context represents context.Context.
4444
type context interface {
45-
Value(key interface{}) interface{}
45+
Value(key any) any
4646
}
4747

4848
// FromContext returns the FeatureSet from the context, if available.

pkg/lisafs/message.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import (
5252
//
5353
// String() implementations must ensure that the message struct doesn't escape.
5454
// For instance, directly passing the struct to fmt.Sprintf() escapes it
55-
// because of the implicit conversion to interface{}.
55+
// because of the implicit conversion to any.
5656

5757
type marshalFunc func([]byte) []byte
5858
type unmarshalFunc func([]byte) ([]byte, bool)

pkg/log/glog.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var pid = os.Getpid()
4747
// file The file name
4848
// line The line number
4949
// msg The user-supplied message
50-
func (g GoogleEmitter) Emit(depth int, level Level, timestamp time.Time, format string, args ...interface{}) {
50+
func (g GoogleEmitter) Emit(depth int, level Level, timestamp time.Time, format string, args ...any) {
5151
// Log level.
5252
prefix := byte('?')
5353
switch level {

pkg/log/json.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type JSONEmitter struct {
6262
}
6363

6464
// Emit implements Emitter.Emit.
65-
func (e JSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...interface{}) {
65+
func (e JSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...any) {
6666
j := jsonLog{
6767
Msg: fmt.Sprintf(format, v...),
6868
Level: level,

pkg/log/json_k8s.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type K8sJSONEmitter struct {
3333
}
3434

3535
// Emit implements Emitter.Emit.
36-
func (e K8sJSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...interface{}) {
36+
func (e K8sJSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...any) {
3737
j := k8sJSONLog{
3838
Log: fmt.Sprintf(format, v...),
3939
Level: level,

pkg/log/log.go

+23-23
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (l Level) String() string {
8080
type Emitter interface {
8181
// Emit emits the given log statement. This allows for control over the
8282
// timestamp used for logging.
83-
Emit(depth int, level Level, timestamp time.Time, format string, v ...interface{})
83+
Emit(depth int, level Level, timestamp time.Time, format string, v ...any)
8484
}
8585

8686
// Writer writes the output to the given writer.
@@ -144,23 +144,23 @@ func (l *Writer) Write(data []byte) (int, error) {
144144
}
145145

146146
// Emit emits the message.
147-
func (l *Writer) Emit(_ int, _ Level, _ time.Time, format string, args ...interface{}) {
147+
func (l *Writer) Emit(_ int, _ Level, _ time.Time, format string, args ...any) {
148148
fmt.Fprintf(l, format, args...)
149149
}
150150

151151
// MultiEmitter is an emitter that emits to multiple Emitters.
152152
type MultiEmitter []Emitter
153153

154154
// Emit emits to all emitters.
155-
func (m *MultiEmitter) Emit(depth int, level Level, timestamp time.Time, format string, v ...interface{}) {
155+
func (m *MultiEmitter) Emit(depth int, level Level, timestamp time.Time, format string, v ...any) {
156156
for _, e := range *m {
157157
e.Emit(1+depth, level, timestamp, format, v...)
158158
}
159159
}
160160

161161
// TestLogger is implemented by testing.T and testing.B.
162162
type TestLogger interface {
163-
Logf(format string, v ...interface{})
163+
Logf(format string, v ...any)
164164
}
165165

166166
// TestEmitter may be used for wrapping tests.
@@ -169,7 +169,7 @@ type TestEmitter struct {
169169
}
170170

171171
// Emit emits to the TestLogger.
172-
func (t *TestEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...interface{}) {
172+
func (t *TestEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...any) {
173173
t.Logf(format, v...)
174174
}
175175

@@ -179,13 +179,13 @@ func (t *TestEmitter) Emit(_ int, level Level, timestamp time.Time, format strin
179179
// satisfies this interface, and may be passed around as a Logger.
180180
type Logger interface {
181181
// Debugf logs a debug statement.
182-
Debugf(format string, v ...interface{})
182+
Debugf(format string, v ...any)
183183

184184
// Infof logs at an info level.
185-
Infof(format string, v ...interface{})
185+
Infof(format string, v ...any)
186186

187187
// Warningf logs at a warning level.
188-
Warningf(format string, v ...interface{})
188+
Warningf(format string, v ...any)
189189

190190
// IsLogging returns true iff this level is being logged. This may be
191191
// used to short-circuit expensive operations for debugging calls.
@@ -199,36 +199,36 @@ type BasicLogger struct {
199199
}
200200

201201
// Debugf implements logger.Debugf.
202-
func (l *BasicLogger) Debugf(format string, v ...interface{}) {
202+
func (l *BasicLogger) Debugf(format string, v ...any) {
203203
l.DebugfAtDepth(1, format, v...)
204204
}
205205

206206
// Infof implements logger.Infof.
207-
func (l *BasicLogger) Infof(format string, v ...interface{}) {
207+
func (l *BasicLogger) Infof(format string, v ...any) {
208208
l.InfofAtDepth(1, format, v...)
209209
}
210210

211211
// Warningf implements logger.Warningf.
212-
func (l *BasicLogger) Warningf(format string, v ...interface{}) {
212+
func (l *BasicLogger) Warningf(format string, v ...any) {
213213
l.WarningfAtDepth(1, format, v...)
214214
}
215215

216216
// DebugfAtDepth logs at a specific depth.
217-
func (l *BasicLogger) DebugfAtDepth(depth int, format string, v ...interface{}) {
217+
func (l *BasicLogger) DebugfAtDepth(depth int, format string, v ...any) {
218218
if l.IsLogging(Debug) {
219219
l.Emit(1+depth, Debug, time.Now(), format, v...)
220220
}
221221
}
222222

223223
// InfofAtDepth logs at a specific depth.
224-
func (l *BasicLogger) InfofAtDepth(depth int, format string, v ...interface{}) {
224+
func (l *BasicLogger) InfofAtDepth(depth int, format string, v ...any) {
225225
if l.IsLogging(Info) {
226226
l.Emit(1+depth, Info, time.Now(), format, v...)
227227
}
228228
}
229229

230230
// WarningfAtDepth logs at a specific depth.
231-
func (l *BasicLogger) WarningfAtDepth(depth int, format string, v ...interface{}) {
231+
func (l *BasicLogger) WarningfAtDepth(depth int, format string, v ...any) {
232232
if l.IsLogging(Warning) {
233233
l.Emit(1+depth, Warning, time.Now(), format, v...)
234234
}
@@ -275,32 +275,32 @@ func SetLevel(newLevel Level) {
275275
}
276276

277277
// Debugf logs to the global logger.
278-
func Debugf(format string, v ...interface{}) {
278+
func Debugf(format string, v ...any) {
279279
Log().DebugfAtDepth(1, format, v...)
280280
}
281281

282282
// Infof logs to the global logger.
283-
func Infof(format string, v ...interface{}) {
283+
func Infof(format string, v ...any) {
284284
Log().InfofAtDepth(1, format, v...)
285285
}
286286

287287
// Warningf logs to the global logger.
288-
func Warningf(format string, v ...interface{}) {
288+
func Warningf(format string, v ...any) {
289289
Log().WarningfAtDepth(1, format, v...)
290290
}
291291

292292
// DebugfAtDepth logs to the global logger.
293-
func DebugfAtDepth(depth int, format string, v ...interface{}) {
293+
func DebugfAtDepth(depth int, format string, v ...any) {
294294
Log().DebugfAtDepth(1+depth, format, v...)
295295
}
296296

297297
// InfofAtDepth logs to the global logger.
298-
func InfofAtDepth(depth int, format string, v ...interface{}) {
298+
func InfofAtDepth(depth int, format string, v ...any) {
299299
Log().InfofAtDepth(1+depth, format, v...)
300300
}
301301

302302
// WarningfAtDepth logs to the global logger.
303-
func WarningfAtDepth(depth int, format string, v ...interface{}) {
303+
func WarningfAtDepth(depth int, format string, v ...any) {
304304
Log().WarningfAtDepth(1+depth, format, v...)
305305
}
306306

@@ -329,15 +329,15 @@ func Stacks(all bool) []byte {
329329
// goroutine.
330330
//
331331
// This will be print a traceback, tb, as Warningf(format+":\n%s", v..., tb).
332-
func Traceback(format string, v ...interface{}) {
332+
func Traceback(format string, v ...any) {
333333
v = append(v, Stacks(false))
334334
Warningf(format+":\n%s", v...)
335335
}
336336

337337
// TracebackAll logs the given message and dumps a stacktrace of all goroutines.
338338
//
339339
// This will be print a traceback, tb, as Warningf(format+":\n%s", v..., tb).
340-
func TracebackAll(format string, v ...interface{}) {
340+
func TracebackAll(format string, v ...any) {
341341
v = append(v, Stacks(true))
342342
Warningf(format+":\n%s", v...)
343343
}
@@ -350,7 +350,7 @@ func IsLogging(level Level) bool {
350350
// CopyStandardLogTo redirects the stdlib log package global output to the global
351351
// logger for the specified level.
352352
func CopyStandardLogTo(l Level) error {
353-
var f func(string, ...interface{})
353+
var f func(string, ...any)
354354

355355
switch l {
356356
case Debug:

pkg/log/rate_limited.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ type rateLimitedLogger struct {
2525
limit *rate.Limiter
2626
}
2727

28-
func (rl *rateLimitedLogger) Debugf(format string, v ...interface{}) {
28+
func (rl *rateLimitedLogger) Debugf(format string, v ...any) {
2929
if rl.limit.Allow() {
3030
rl.logger.Debugf(format, v...)
3131
}
3232
}
3333

34-
func (rl *rateLimitedLogger) Infof(format string, v ...interface{}) {
34+
func (rl *rateLimitedLogger) Infof(format string, v ...any) {
3535
if rl.limit.Allow() {
3636
rl.logger.Infof(format, v...)
3737
}
3838
}
3939

40-
func (rl *rateLimitedLogger) Warningf(format string, v ...interface{}) {
40+
func (rl *rateLimitedLogger) Warningf(format string, v ...any) {
4141
if rl.limit.Allow() {
4242
rl.logger.Warningf(format, v...)
4343
}

0 commit comments

Comments
 (0)