aboutsummaryrefslogtreecommitdiff
path: root/src/context
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/context
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/context')
-rw-r--r--src/context/context.go16
-rw-r--r--src/context/context_test.go20
2 files changed, 18 insertions, 18 deletions
diff --git a/src/context/context.go b/src/context/context.go
index a9e14703fd..cf010b2a69 100644
--- a/src/context/context.go
+++ b/src/context/context.go
@@ -150,7 +150,7 @@ type Context interface {
// u, ok := ctx.Value(userKey).(*User)
// return u, ok
// }
- Value(key interface{}) interface{}
+ Value(key any) any
}
// Canceled is the error returned by Context.Err when the context is canceled.
@@ -182,7 +182,7 @@ func (*emptyCtx) Err() error {
return nil
}
-func (*emptyCtx) Value(key interface{}) interface{} {
+func (*emptyCtx) Value(key any) any {
return nil
}
@@ -348,7 +348,7 @@ type cancelCtx struct {
err error // set to non-nil by the first cancel call
}
-func (c *cancelCtx) Value(key interface{}) interface{} {
+func (c *cancelCtx) Value(key any) any {
if key == &cancelCtxKey {
return c
}
@@ -520,7 +520,7 @@ func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
// interface{}, context keys often have concrete type
// struct{}. Alternatively, exported context key variables' static
// type should be a pointer or interface.
-func WithValue(parent Context, key, val interface{}) Context {
+func WithValue(parent Context, key, val any) Context {
if parent == nil {
panic("cannot create context from nil parent")
}
@@ -537,13 +537,13 @@ func WithValue(parent Context, key, val interface{}) Context {
// delegates all other calls to the embedded Context.
type valueCtx struct {
Context
- key, val interface{}
+ key, val any
}
// stringify tries a bit to stringify v, without using fmt, since we don't
// want context depending on the unicode tables. This is only used by
// *valueCtx.String().
-func stringify(v interface{}) string {
+func stringify(v any) string {
switch s := v.(type) {
case stringer:
return s.String()
@@ -559,14 +559,14 @@ func (c *valueCtx) String() string {
", val " + stringify(c.val) + ")"
}
-func (c *valueCtx) Value(key interface{}) interface{} {
+func (c *valueCtx) Value(key any) any {
if c.key == key {
return c.val
}
return value(c.Context, key)
}
-func value(c Context, key interface{}) interface{} {
+func value(c Context, key any) any {
for {
switch ctx := c.(type) {
case *valueCtx:
diff --git a/src/context/context_test.go b/src/context/context_test.go
index a2e2324a0e..8673c0fdea 100644
--- a/src/context/context_test.go
+++ b/src/context/context_test.go
@@ -16,21 +16,21 @@ import (
type testingT interface {
Deadline() (time.Time, bool)
- Error(args ...interface{})
- Errorf(format string, args ...interface{})
+ Error(args ...any)
+ Errorf(format string, args ...any)
Fail()
FailNow()
Failed() bool
- Fatal(args ...interface{})
- Fatalf(format string, args ...interface{})
+ Fatal(args ...any)
+ Fatalf(format string, args ...any)
Helper()
- Log(args ...interface{})
- Logf(format string, args ...interface{})
+ Log(args ...any)
+ Logf(format string, args ...any)
Name() string
Parallel()
- Skip(args ...interface{})
+ Skip(args ...any)
SkipNow()
- Skipf(format string, args ...interface{})
+ Skipf(format string, args ...any)
Skipped() bool
}
@@ -553,7 +553,7 @@ func testLayers(t testingT, seed int64, testTimeout bool) {
t.Parallel()
r := rand.New(rand.NewSource(seed))
- errorf := func(format string, a ...interface{}) {
+ errorf := func(format string, a ...any) {
t.Errorf(fmt.Sprintf("seed=%d: %s", seed, format), a...)
}
const (
@@ -691,7 +691,7 @@ func XTestInvalidDerivedFail(t testingT) {
}
}
-func recoveredValue(fn func()) (v interface{}) {
+func recoveredValue(fn func()) (v any) {
defer func() { v = recover() }()
fn()
return