diff options
| author | Russ Cox <rsc@golang.org> | 2021-12-01 12:15:45 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2021-12-13 18:45:54 +0000 |
| commit | 2580d0e08d5e9f979b943758d3c49877fb2324cb (patch) | |
| tree | 3aafccfd81087734156a1778ce2321adf345f271 /src/errors | |
| parent | 083ef5462494e81ee23316245c5d65085a3f62d9 (diff) | |
| download | go-2580d0e08d5e9f979b943758d3c49877fb2324cb.tar.xz | |
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/errors')
| -rw-r--r-- | src/errors/wrap.go | 4 | ||||
| -rw-r--r-- | src/errors/wrap_test.go | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/errors/wrap.go b/src/errors/wrap.go index ab3cdb86d3..263ae16b48 100644 --- a/src/errors/wrap.go +++ b/src/errors/wrap.go @@ -75,7 +75,7 @@ func Is(err, target error) bool { // // As panics if target is not a non-nil pointer to either a type that implements // error, or to any interface type. -func As(err error, target interface{}) bool { +func As(err error, target any) bool { if target == nil { panic("errors: target cannot be nil") } @@ -93,7 +93,7 @@ func As(err error, target interface{}) bool { val.Elem().Set(reflectlite.ValueOf(err)) return true } - if x, ok := err.(interface{ As(interface{}) bool }); ok && x.As(target) { + if x, ok := err.(interface{ As(any) bool }); ok && x.As(target) { return true } err = Unwrap(err) diff --git a/src/errors/wrap_test.go b/src/errors/wrap_test.go index a22fee2f04..eb8314b04b 100644 --- a/src/errors/wrap_test.go +++ b/src/errors/wrap_test.go @@ -66,7 +66,7 @@ var poserPathErr = &fs.PathError{Op: "poser"} func (p *poser) Error() string { return p.msg } func (p *poser) Is(err error) bool { return p.f(err) } -func (p *poser) As(err interface{}) bool { +func (p *poser) As(err any) bool { switch x := err.(type) { case **poser: *x = p @@ -90,9 +90,9 @@ func TestAs(t *testing.T) { testCases := []struct { err error - target interface{} + target any match bool - want interface{} // value of target on match + want any // value of target on match }{{ nil, &errP, @@ -171,7 +171,7 @@ func TestAs(t *testing.T) { func TestAsValidation(t *testing.T) { var s string - testCases := []interface{}{ + testCases := []any{ nil, (*int)(nil), "error", |
