xerrors: use any [generated]
[git-generate]
gofmt -r 'interface{} -> any' -w .
Change-Id: I2ea2c800cd1485d57535f3b1446be728e8f5c2dd
Reviewed-on: https://go-review.googlesource.com/c/xerrors/+/610076
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
diff --git a/adaptor.go b/adaptor.go
index 4317f24..c3c5f8e 100644
--- a/adaptor.go
+++ b/adaptor.go
@@ -175,13 +175,13 @@
// printer wraps a state to implement an xerrors.Printer.
type printer state
-func (s *printer) Print(args ...interface{}) {
+func (s *printer) Print(args ...any) {
if !s.inDetail || s.printDetail {
fmt.Fprint((*state)(s), args...)
}
}
-func (s *printer) Printf(format string, args ...interface{}) {
+func (s *printer) Printf(format string, args ...any) {
if !s.inDetail || s.printDetail {
fmt.Fprintf((*state)(s), format, args...)
}
diff --git a/fmt.go b/fmt.go
index 27a5d70..268f28f 100644
--- a/fmt.go
+++ b/fmt.go
@@ -36,7 +36,7 @@
//
// Note that as of Go 1.13, the fmt.Errorf function will do error formatting,
// but it will not capture a stack backtrace.
-func Errorf(format string, a ...interface{}) error {
+func Errorf(format string, a ...any) error {
format = formatPlusW(format)
// Support a ": %[wsv]" suffix, which works well with xerrors.Formatter.
wrap := strings.HasSuffix(format, ": %w")
@@ -81,7 +81,7 @@
return &wrapError{msg, err, frame}
}
-func errorAt(args []interface{}, i int) error {
+func errorAt(args []any, i int) error {
if i < 0 || i >= len(args) {
return nil
}
diff --git a/fmt_test.go b/fmt_test.go
index 1ee7e6f..d3d7bec 100644
--- a/fmt_test.go
+++ b/fmt_test.go
@@ -527,10 +527,10 @@
type fmtTwiceErr struct {
format string
- args []interface{}
+ args []any
}
-func fmtTwice(format string, a ...interface{}) error {
+func fmtTwice(format string, a ...any) error {
return fmtTwiceErr{format, a}
}
@@ -588,11 +588,11 @@
str string
}
-func (p *testPrinter) Print(a ...interface{}) {
+func (p *testPrinter) Print(a ...any) {
p.str += fmt.Sprint(a...)
}
-func (p *testPrinter) Printf(format string, a ...interface{}) {
+func (p *testPrinter) Printf(format string, a ...any) {
p.str += fmt.Sprintf(format, a...)
}
diff --git a/format.go b/format.go
index 1bc9c26..9e5ec6c 100644
--- a/format.go
+++ b/format.go
@@ -20,10 +20,10 @@
// typically provide their own implementations.
type Printer interface {
// Print appends args to the message output.
- Print(args ...interface{})
+ Print(args ...any)
// Printf writes a formatted string.
- Printf(format string, args ...interface{})
+ Printf(format string, args ...any)
// Detail reports whether error detail is requested.
// After the first call to Detail, all text written to the Printer
diff --git a/stack_test.go b/stack_test.go
index e13f319..cb6c0e5 100644
--- a/stack_test.go
+++ b/stack_test.go
@@ -24,11 +24,11 @@
err := xerrors.New("foo")
// pi := big.NewFloat(3.14) // Something expensive.
num := big.NewInt(5)
- args := func(a ...interface{}) []interface{} { return a }
+ args := func(a ...any) []any { return a }
benchCases := []struct {
name string
format string
- args []interface{}
+ args []any
}{
{"no_format", "msg: %v", args(err)},
{"with_format", "failed %d times: %v", args(5, err)},
diff --git a/wrap.go b/wrap.go
index 9842758..3cc27dc 100644
--- a/wrap.go
+++ b/wrap.go
@@ -83,7 +83,7 @@
// matches the type to which target points.
//
// Deprecated: As of Go 1.13, use errors.As instead.
-func As(err error, target interface{}) bool {
+func As(err error, target any) bool {
if target == nil {
panic("errors: target cannot be nil")
}
@@ -101,7 +101,7 @@
val.Elem().Set(reflect.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/wrap_test.go b/wrap_test.go
index 56e0dc8..fb9a840 100644
--- a/wrap_test.go
+++ b/wrap_test.go
@@ -71,7 +71,7 @@
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
@@ -108,7 +108,7 @@
testCases := []struct {
err error
- target interface{}
+ target any
match bool
}{{
nil,
@@ -178,7 +178,7 @@
func TestAsValidation(t *testing.T) {
var s string
- testCases := []interface{}{
+ testCases := []any{
nil,
(*int)(nil),
"error",