convert uses of interface{} to any

Done via:
  find . -name "*.go" | xargs sed -i -E 's/interface\{\}/any/g'

PiperOrigin-RevId: 487033228
This commit is contained in:
Kevin Krakauer
2022-11-08 13:12:12 -08:00
committed by gVisor bot
parent c82b70015d
commit d8aa09e04c
220 changed files with 509 additions and 509 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
module gvisor.dev/gvisor
go 1.17
go 1.18
require (
github.com/BurntSushi/toml v0.3.1
+1 -1
View File
@@ -21,7 +21,7 @@ import (
func TestSizes(t *testing.T) {
testCases := []struct {
typ interface{}
typ any
defined uintptr
}{
{IPTEntry{}, SizeOfIPTEntry},
+3 -3
View File
@@ -59,7 +59,7 @@ func AppendUint64(buf []byte, order binary.ByteOrder, num uint64) []byte {
// data must only contain fixed-length signed and unsigned ints, arrays,
// slices, structs and compositions of said types. data may be a pointer,
// but cannot contain pointers.
func Marshal(buf []byte, order binary.ByteOrder, data interface{}) []byte {
func Marshal(buf []byte, order binary.ByteOrder, data any) []byte {
return marshal(buf, order, reflect.Indirect(reflect.ValueOf(data)))
}
@@ -104,7 +104,7 @@ func marshal(buf []byte, order binary.ByteOrder, data reflect.Value) []byte {
// data must be a slice or a pointer and buf must have a length of exactly
// Size(data). data must only contain fixed-length signed and unsigned ints,
// arrays, slices, structs and compositions of said types.
func Unmarshal(buf []byte, order binary.ByteOrder, data interface{}) {
func Unmarshal(buf []byte, order binary.ByteOrder, data any) {
value := reflect.ValueOf(data)
switch value.Kind() {
case reflect.Ptr:
@@ -170,7 +170,7 @@ func unmarshal(buf []byte, order binary.ByteOrder, data reflect.Value) []byte {
// Size calculates the buffer sized needed by Marshal or Unmarshal.
//
// Size only support the types supported by Marshal.
func Size(v interface{}) uintptr {
func Size(v any) uintptr {
return sizeof(reflect.Indirect(reflect.ValueOf(v)))
}
+7 -7
View File
@@ -38,18 +38,18 @@ func TestSize(t *testing.T) {
func TestPanic(t *testing.T) {
tests := []struct {
name string
f func([]byte, binary.ByteOrder, interface{})
data interface{}
f func([]byte, binary.ByteOrder, any)
data any
want string
}{
{"Unmarshal int", Unmarshal, 5, "invalid type: int"},
{"Unmarshal []int", Unmarshal, []int{5}, "invalid type: int"},
{"Marshal int", func(_ []byte, bo binary.ByteOrder, d interface{}) { Marshal(nil, bo, d) }, 5, "invalid type: int"},
{"Marshal int[]", func(_ []byte, bo binary.ByteOrder, d interface{}) { Marshal(nil, bo, d) }, []int{5}, "invalid type: int"},
{"Marshal int", func(_ []byte, bo binary.ByteOrder, d any) { Marshal(nil, bo, d) }, 5, "invalid type: int"},
{"Marshal int[]", func(_ []byte, bo binary.ByteOrder, d any) { Marshal(nil, bo, d) }, []int{5}, "invalid type: int"},
{"Unmarshal short buffer", Unmarshal, newInt32(5), "runtime error: index out of range"},
{"Unmarshal long buffer", func(_ []byte, bo binary.ByteOrder, d interface{}) { Unmarshal(make([]byte, 50), bo, d) }, newInt32(5), "buffer too long by 46 bytes"},
{"marshal int", func(_ []byte, bo binary.ByteOrder, d interface{}) { marshal(nil, bo, reflect.ValueOf(d)) }, 5, "invalid type: int"},
{"Size int", func(_ []byte, _ binary.ByteOrder, d interface{}) { Size(d) }, 5, "invalid type: int"},
{"Unmarshal long buffer", func(_ []byte, bo binary.ByteOrder, d any) { Unmarshal(make([]byte, 50), bo, d) }, newInt32(5), "buffer too long by 46 bytes"},
{"marshal int", func(_ []byte, bo binary.ByteOrder, d any) { marshal(nil, bo, reflect.ValueOf(d)) }, 5, "invalid type: int"},
{"Size int", func(_ []byte, _ binary.ByteOrder, d any) { Size(d) }, 5, "invalid type: int"},
}
for _, test := range tests {
+1 -1
View File
@@ -53,7 +53,7 @@ var chunkPools [numPools]sync.Pool
func init() {
for i := 0; i < numPools; i++ {
chunkSize := baseChunkSize * (1 << i)
chunkPools[i].New = func() interface{} {
chunkPools[i].New = func() any {
return &chunk{
data: make([]byte, chunkSize),
}
+1 -1
View File
@@ -26,7 +26,7 @@ import (
const ReadSize = 512
var viewPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &View{}
},
}
+2 -2
View File
@@ -58,13 +58,13 @@ import (
)
var bufPool = sync.Pool{
New: func() interface{} {
New: func() any {
return bytes.NewBuffer(nil)
},
}
var chunkPool = sync.Pool{
New: func() interface{} {
New: func() any {
return new(chunk)
},
}
+3 -3
View File
@@ -27,9 +27,9 @@ import (
)
type harness interface {
Errorf(format string, v ...interface{})
Fatalf(format string, v ...interface{})
Logf(format string, v ...interface{})
Errorf(format string, v ...any)
Fatalf(format string, v ...any)
Logf(format string, v ...any)
}
func initTest(t harness, size int) []byte {
+4 -4
View File
@@ -186,7 +186,7 @@ func Background() Context {
// WithValue returns a copy of parent in which the value associated with key is
// val.
func WithValue(parent Context, key, val interface{}) Context {
func WithValue(parent Context, key, val any) Context {
return &withValue{
Context: parent,
key: key,
@@ -196,12 +196,12 @@ func WithValue(parent Context, key, val interface{}) Context {
type withValue struct {
Context
key interface{}
val interface{}
key any
val any
}
// Value implements Context.Value.
func (ctx *withValue) Value(key interface{}) interface{} {
func (ctx *withValue) Value(key any) any {
if key == ctx.key {
return ctx.val
}
+1 -1
View File
@@ -124,7 +124,7 @@ func (s *Server) serve() {
}
// Register registers a specific control interface with the server.
func (s *Server) Register(obj interface{}) {
func (s *Server) Register(obj any) {
s.server.Register(obj)
}
+1 -1
View File
@@ -113,7 +113,7 @@ func ClearCoverageData() {
}
var coveragePool = sync.Pool{
New: func() interface{} {
New: func() any {
return make([]byte, 0)
},
}
+1 -1
View File
@@ -42,7 +42,7 @@ const (
// context represents context.Context.
type context interface {
Value(key interface{}) interface{}
Value(key any) any
}
// FromContext returns the FeatureSet from the context, if available.
+1 -1
View File
@@ -52,7 +52,7 @@ import (
//
// String() implementations must ensure that the message struct doesn't escape.
// For instance, directly passing the struct to fmt.Sprintf() escapes it
// because of the implicit conversion to interface{}.
// because of the implicit conversion to any.
type marshalFunc func([]byte) []byte
type unmarshalFunc func([]byte) ([]byte, bool)
+1 -1
View File
@@ -47,7 +47,7 @@ var pid = os.Getpid()
// file The file name
// line The line number
// msg The user-supplied message
func (g GoogleEmitter) Emit(depth int, level Level, timestamp time.Time, format string, args ...interface{}) {
func (g GoogleEmitter) Emit(depth int, level Level, timestamp time.Time, format string, args ...any) {
// Log level.
prefix := byte('?')
switch level {
+1 -1
View File
@@ -62,7 +62,7 @@ type JSONEmitter struct {
}
// Emit implements Emitter.Emit.
func (e JSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...interface{}) {
func (e JSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...any) {
j := jsonLog{
Msg: fmt.Sprintf(format, v...),
Level: level,
+1 -1
View File
@@ -33,7 +33,7 @@ type K8sJSONEmitter struct {
}
// Emit implements Emitter.Emit.
func (e K8sJSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...interface{}) {
func (e K8sJSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...any) {
j := k8sJSONLog{
Log: fmt.Sprintf(format, v...),
Level: level,
+23 -23
View File
@@ -80,7 +80,7 @@ func (l Level) String() string {
type Emitter interface {
// Emit emits the given log statement. This allows for control over the
// timestamp used for logging.
Emit(depth int, level Level, timestamp time.Time, format string, v ...interface{})
Emit(depth int, level Level, timestamp time.Time, format string, v ...any)
}
// Writer writes the output to the given writer.
@@ -144,7 +144,7 @@ func (l *Writer) Write(data []byte) (int, error) {
}
// Emit emits the message.
func (l *Writer) Emit(_ int, _ Level, _ time.Time, format string, args ...interface{}) {
func (l *Writer) Emit(_ int, _ Level, _ time.Time, format string, args ...any) {
fmt.Fprintf(l, format, args...)
}
@@ -152,7 +152,7 @@ func (l *Writer) Emit(_ int, _ Level, _ time.Time, format string, args ...interf
type MultiEmitter []Emitter
// Emit emits to all emitters.
func (m *MultiEmitter) Emit(depth int, level Level, timestamp time.Time, format string, v ...interface{}) {
func (m *MultiEmitter) Emit(depth int, level Level, timestamp time.Time, format string, v ...any) {
for _, e := range *m {
e.Emit(1+depth, level, timestamp, format, v...)
}
@@ -160,7 +160,7 @@ func (m *MultiEmitter) Emit(depth int, level Level, timestamp time.Time, format
// TestLogger is implemented by testing.T and testing.B.
type TestLogger interface {
Logf(format string, v ...interface{})
Logf(format string, v ...any)
}
// TestEmitter may be used for wrapping tests.
@@ -169,7 +169,7 @@ type TestEmitter struct {
}
// Emit emits to the TestLogger.
func (t *TestEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...interface{}) {
func (t *TestEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...any) {
t.Logf(format, v...)
}
@@ -179,13 +179,13 @@ func (t *TestEmitter) Emit(_ int, level Level, timestamp time.Time, format strin
// satisfies this interface, and may be passed around as a Logger.
type Logger interface {
// Debugf logs a debug statement.
Debugf(format string, v ...interface{})
Debugf(format string, v ...any)
// Infof logs at an info level.
Infof(format string, v ...interface{})
Infof(format string, v ...any)
// Warningf logs at a warning level.
Warningf(format string, v ...interface{})
Warningf(format string, v ...any)
// IsLogging returns true iff this level is being logged. This may be
// used to short-circuit expensive operations for debugging calls.
@@ -199,36 +199,36 @@ type BasicLogger struct {
}
// Debugf implements logger.Debugf.
func (l *BasicLogger) Debugf(format string, v ...interface{}) {
func (l *BasicLogger) Debugf(format string, v ...any) {
l.DebugfAtDepth(1, format, v...)
}
// Infof implements logger.Infof.
func (l *BasicLogger) Infof(format string, v ...interface{}) {
func (l *BasicLogger) Infof(format string, v ...any) {
l.InfofAtDepth(1, format, v...)
}
// Warningf implements logger.Warningf.
func (l *BasicLogger) Warningf(format string, v ...interface{}) {
func (l *BasicLogger) Warningf(format string, v ...any) {
l.WarningfAtDepth(1, format, v...)
}
// DebugfAtDepth logs at a specific depth.
func (l *BasicLogger) DebugfAtDepth(depth int, format string, v ...interface{}) {
func (l *BasicLogger) DebugfAtDepth(depth int, format string, v ...any) {
if l.IsLogging(Debug) {
l.Emit(1+depth, Debug, time.Now(), format, v...)
}
}
// InfofAtDepth logs at a specific depth.
func (l *BasicLogger) InfofAtDepth(depth int, format string, v ...interface{}) {
func (l *BasicLogger) InfofAtDepth(depth int, format string, v ...any) {
if l.IsLogging(Info) {
l.Emit(1+depth, Info, time.Now(), format, v...)
}
}
// WarningfAtDepth logs at a specific depth.
func (l *BasicLogger) WarningfAtDepth(depth int, format string, v ...interface{}) {
func (l *BasicLogger) WarningfAtDepth(depth int, format string, v ...any) {
if l.IsLogging(Warning) {
l.Emit(1+depth, Warning, time.Now(), format, v...)
}
@@ -275,32 +275,32 @@ func SetLevel(newLevel Level) {
}
// Debugf logs to the global logger.
func Debugf(format string, v ...interface{}) {
func Debugf(format string, v ...any) {
Log().DebugfAtDepth(1, format, v...)
}
// Infof logs to the global logger.
func Infof(format string, v ...interface{}) {
func Infof(format string, v ...any) {
Log().InfofAtDepth(1, format, v...)
}
// Warningf logs to the global logger.
func Warningf(format string, v ...interface{}) {
func Warningf(format string, v ...any) {
Log().WarningfAtDepth(1, format, v...)
}
// DebugfAtDepth logs to the global logger.
func DebugfAtDepth(depth int, format string, v ...interface{}) {
func DebugfAtDepth(depth int, format string, v ...any) {
Log().DebugfAtDepth(1+depth, format, v...)
}
// InfofAtDepth logs to the global logger.
func InfofAtDepth(depth int, format string, v ...interface{}) {
func InfofAtDepth(depth int, format string, v ...any) {
Log().InfofAtDepth(1+depth, format, v...)
}
// WarningfAtDepth logs to the global logger.
func WarningfAtDepth(depth int, format string, v ...interface{}) {
func WarningfAtDepth(depth int, format string, v ...any) {
Log().WarningfAtDepth(1+depth, format, v...)
}
@@ -329,7 +329,7 @@ func Stacks(all bool) []byte {
// goroutine.
//
// This will be print a traceback, tb, as Warningf(format+":\n%s", v..., tb).
func Traceback(format string, v ...interface{}) {
func Traceback(format string, v ...any) {
v = append(v, Stacks(false))
Warningf(format+":\n%s", v...)
}
@@ -337,7 +337,7 @@ func Traceback(format string, v ...interface{}) {
// TracebackAll logs the given message and dumps a stacktrace of all goroutines.
//
// This will be print a traceback, tb, as Warningf(format+":\n%s", v..., tb).
func TracebackAll(format string, v ...interface{}) {
func TracebackAll(format string, v ...any) {
v = append(v, Stacks(true))
Warningf(format+":\n%s", v...)
}
@@ -350,7 +350,7 @@ func IsLogging(level Level) bool {
// CopyStandardLogTo redirects the stdlib log package global output to the global
// logger for the specified level.
func CopyStandardLogTo(l Level) error {
var f func(string, ...interface{})
var f func(string, ...any)
switch l {
case Debug:
+3 -3
View File
@@ -25,19 +25,19 @@ type rateLimitedLogger struct {
limit *rate.Limiter
}
func (rl *rateLimitedLogger) Debugf(format string, v ...interface{}) {
func (rl *rateLimitedLogger) Debugf(format string, v ...any) {
if rl.limit.Allow() {
rl.logger.Debugf(format, v...)
}
}
func (rl *rateLimitedLogger) Infof(format string, v ...interface{}) {
func (rl *rateLimitedLogger) Infof(format string, v ...any) {
if rl.limit.Allow() {
rl.logger.Infof(format, v...)
}
}
func (rl *rateLimitedLogger) Warningf(format string, v ...interface{}) {
func (rl *rateLimitedLogger) Warningf(format string, v ...any) {
if rl.limit.Allow() {
rl.logger.Warningf(format, v...)
}
+2 -2
View File
@@ -842,7 +842,7 @@ func (m *metricSet) Values() metricValues {
m.mu.Unlock()
vals := metricValues{
uint64Metrics: make(map[string]interface{}, len(m.uint64Metrics)),
uint64Metrics: make(map[string]any, len(m.uint64Metrics)),
distributionMetrics: make(map[string][][]uint64, len(m.distributionMetrics)),
distributionTotalSamples: make(map[string][]uint64, len(m.distributionMetrics)),
stages: stages,
@@ -894,7 +894,7 @@ type metricValues struct {
// uint64Metrics is a map of uint64 metrics,
// with key as metric name. Value can be either uint64, or map[string]uint64
// to support metrics with one field.
uint64Metrics map[string]interface{}
uint64Metrics map[string]any
// distributionMetrics is a map of distribution metrics.
// The first key level is the metric name.
+1 -1
View File
@@ -796,7 +796,7 @@ func TestBucketerPanics(t *testing.T) {
},
} {
t.Run(name, func(t *testing.T) {
var recovered interface{}
var recovered any
func() {
defer func() {
recovered = recover()

Some files were not shown because too many files have changed in this diff Show More