Skip to content

Commit 0c47e2b

Browse files
dmitshurgopherbot
authored andcommittedSep 3, 2024·
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 <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent cf14814 commit 0c47e2b

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed
 

‎adaptor.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ func (s *state) Write(b []byte) (n int, err error) {
175175
// printer wraps a state to implement an xerrors.Printer.
176176
type printer state
177177

178-
func (s *printer) Print(args ...interface{}) {
178+
func (s *printer) Print(args ...any) {
179179
if !s.inDetail || s.printDetail {
180180
fmt.Fprint((*state)(s), args...)
181181
}
182182
}
183183

184-
func (s *printer) Printf(format string, args ...interface{}) {
184+
func (s *printer) Printf(format string, args ...any) {
185185
if !s.inDetail || s.printDetail {
186186
fmt.Fprintf((*state)(s), format, args...)
187187
}

‎fmt.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const percentBangString = "%!"
3636
//
3737
// Note that as of Go 1.13, the fmt.Errorf function will do error formatting,
3838
// but it will not capture a stack backtrace.
39-
func Errorf(format string, a ...interface{}) error {
39+
func Errorf(format string, a ...any) error {
4040
format = formatPlusW(format)
4141
// Support a ": %[wsv]" suffix, which works well with xerrors.Formatter.
4242
wrap := strings.HasSuffix(format, ": %w")
@@ -81,7 +81,7 @@ func Errorf(format string, a ...interface{}) error {
8181
return &wrapError{msg, err, frame}
8282
}
8383

84-
func errorAt(args []interface{}, i int) error {
84+
func errorAt(args []any, i int) error {
8585
if i < 0 || i >= len(args) {
8686
return nil
8787
}

‎fmt_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,10 @@ func (e formatError) GoString() string {
527527

528528
type fmtTwiceErr struct {
529529
format string
530-
args []interface{}
530+
args []any
531531
}
532532

533-
func fmtTwice(format string, a ...interface{}) error {
533+
func fmtTwice(format string, a ...any) error {
534534
return fmtTwiceErr{format, a}
535535
}
536536

@@ -588,11 +588,11 @@ type testPrinter struct {
588588
str string
589589
}
590590

591-
func (p *testPrinter) Print(a ...interface{}) {
591+
func (p *testPrinter) Print(a ...any) {
592592
p.str += fmt.Sprint(a...)
593593
}
594594

595-
func (p *testPrinter) Printf(format string, a ...interface{}) {
595+
func (p *testPrinter) Printf(format string, a ...any) {
596596
p.str += fmt.Sprintf(format, a...)
597597
}
598598

‎format.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ type Formatter interface {
2020
// typically provide their own implementations.
2121
type Printer interface {
2222
// Print appends args to the message output.
23-
Print(args ...interface{})
23+
Print(args ...any)
2424

2525
// Printf writes a formatted string.
26-
Printf(format string, args ...interface{})
26+
Printf(format string, args ...any)
2727

2828
// Detail reports whether error detail is requested.
2929
// After the first call to Detail, all text written to the Printer

‎stack_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ func BenchmarkErrorf(b *testing.B) {
2424
err := xerrors.New("foo")
2525
// pi := big.NewFloat(3.14) // Something expensive.
2626
num := big.NewInt(5)
27-
args := func(a ...interface{}) []interface{} { return a }
27+
args := func(a ...any) []any { return a }
2828
benchCases := []struct {
2929
name string
3030
format string
31-
args []interface{}
31+
args []any
3232
}{
3333
{"no_format", "msg: %v", args(err)},
3434
{"with_format", "failed %d times: %v", args(5, err)},

‎wrap.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func Is(err, target error) bool {
8383
// matches the type to which target points.
8484
//
8585
// Deprecated: As of Go 1.13, use errors.As instead.
86-
func As(err error, target interface{}) bool {
86+
func As(err error, target any) bool {
8787
if target == nil {
8888
panic("errors: target cannot be nil")
8989
}
@@ -101,7 +101,7 @@ func As(err error, target interface{}) bool {
101101
val.Elem().Set(reflect.ValueOf(err))
102102
return true
103103
}
104-
if x, ok := err.(interface{ As(interface{}) bool }); ok && x.As(target) {
104+
if x, ok := err.(interface{ As(any) bool }); ok && x.As(target) {
105105
return true
106106
}
107107
err = Unwrap(err)

‎wrap_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type poser struct {
7171

7272
func (p *poser) Error() string { return p.msg }
7373
func (p *poser) Is(err error) bool { return p.f(err) }
74-
func (p *poser) As(err interface{}) bool {
74+
func (p *poser) As(err any) bool {
7575
switch x := err.(type) {
7676
case **poser:
7777
*x = p
@@ -108,7 +108,7 @@ func TestAs(t *testing.T) {
108108

109109
testCases := []struct {
110110
err error
111-
target interface{}
111+
target any
112112
match bool
113113
}{{
114114
nil,
@@ -178,7 +178,7 @@ func TestAs(t *testing.T) {
178178

179179
func TestAsValidation(t *testing.T) {
180180
var s string
181-
testCases := []interface{}{
181+
testCases := []any{
182182
nil,
183183
(*int)(nil),
184184
"error",

0 commit comments

Comments
 (0)
Please sign in to comment.