From 32f3770ec51a8317214ac5b3725fb827c5b98e86 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 27 Oct 2011 18:03:52 -0700 Subject: [PATCH] pkg: remove .String() from some print arguments I found these by adding a check to govet, but the check produces far too many false positives to be useful. Even so, these few seem worth cleaning up. R=golang-dev, bradfitz, iant CC=golang-dev https://golang.org/cl/5311067 --- src/pkg/crypto/bcrypt/bcrypt_test.go | 2 +- src/pkg/exp/gui/x11/conn.go | 6 +++--- src/pkg/expvar/expvar.go | 2 +- src/pkg/go/ast/print.go | 6 +++--- src/pkg/go/scanner/errors.go | 2 +- src/pkg/go/scanner/scanner_test.go | 8 ++++---- src/pkg/gob/decode.go | 4 ++-- src/pkg/gob/encode.go | 2 +- src/pkg/smtp/smtp_test.go | 22 +++++++++++----------- src/pkg/strconv/fp_test.go | 2 +- 10 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/pkg/crypto/bcrypt/bcrypt_test.go b/src/pkg/crypto/bcrypt/bcrypt_test.go index 89eca0a4488..3efbc1c46f2 100644 --- a/src/pkg/crypto/bcrypt/bcrypt_test.go +++ b/src/pkg/crypto/bcrypt/bcrypt_test.go @@ -86,7 +86,7 @@ func TestInvalidHashErrors(t *testing.T) { t.Errorf("%s: Should have returned an error", name) } if err != nil && err != expected { - t.Errorf("%s gave err %v but should have given %v", name, err.String(), expected.String()) + t.Errorf("%s gave err %v but should have given %v", name, err, expected) } } for _, iht := range invalidTests { diff --git a/src/pkg/exp/gui/x11/conn.go b/src/pkg/exp/gui/x11/conn.go index bf94bcaabb4..f4a453ede4d 100644 --- a/src/pkg/exp/gui/x11/conn.go +++ b/src/pkg/exp/gui/x11/conn.go @@ -87,7 +87,7 @@ func (c *conn) writeSocket() { setU32LE(c.flushBuf0[16:20], uint32(y<<16)) if _, err := c.w.Write(c.flushBuf0[:24]); err != nil { if err != os.EOF { - log.Println("x11:", err.String()) + log.Println("x11:", err) } return } @@ -106,7 +106,7 @@ func (c *conn) writeSocket() { x += nx if _, err := c.w.Write(c.flushBuf1[:nx]); err != nil { if err != os.EOF { - log.Println("x11:", err.String()) + log.Println("x11:", err) } return } @@ -114,7 +114,7 @@ func (c *conn) writeSocket() { } if err := c.w.Flush(); err != nil { if err != os.EOF { - log.Println("x11:", err.String()) + log.Println("x11:", err) } return } diff --git a/src/pkg/expvar/expvar.go b/src/pkg/expvar/expvar.go index 7b733faf674..f5d6ed586c8 100644 --- a/src/pkg/expvar/expvar.go +++ b/src/pkg/expvar/expvar.go @@ -102,7 +102,7 @@ func (v *Map) String() string { if !first { fmt.Fprintf(b, ", ") } - fmt.Fprintf(b, "\"%s\": %v", key, val.String()) + fmt.Fprintf(b, "\"%s\": %v", key, val) first = false } fmt.Fprintf(b, "}") diff --git a/src/pkg/go/ast/print.go b/src/pkg/go/ast/print.go index 62a30481d5c..e36f99fdf02 100644 --- a/src/pkg/go/ast/print.go +++ b/src/pkg/go/ast/print.go @@ -149,7 +149,7 @@ func (p *printer) print(x reflect.Value) { p.print(x.Elem()) case reflect.Map: - p.printf("%s (len = %d) {\n", x.Type().String(), x.Len()) + p.printf("%s (len = %d) {\n", x.Type(), x.Len()) p.indent++ for _, key := range x.MapKeys() { p.print(key) @@ -178,7 +178,7 @@ func (p *printer) print(x reflect.Value) { p.printf("%#q", s) return } - p.printf("%s (len = %d) {\n", x.Type().String(), x.Len()) + p.printf("%s (len = %d) {\n", x.Type(), x.Len()) p.indent++ for i, n := 0, x.Len(); i < n; i++ { p.printf("%d: ", i) @@ -189,7 +189,7 @@ func (p *printer) print(x reflect.Value) { p.printf("}") case reflect.Struct: - p.printf("%s {\n", x.Type().String()) + p.printf("%s {\n", x.Type()) p.indent++ t := x.Type() for i, n := 0, t.NumField(); i < n; i++ { diff --git a/src/pkg/go/scanner/errors.go b/src/pkg/go/scanner/errors.go index a0927e4167f..df2a46bc226 100644 --- a/src/pkg/go/scanner/errors.go +++ b/src/pkg/go/scanner/errors.go @@ -92,7 +92,7 @@ func (p ErrorList) String() string { case 1: return p[0].String() } - return fmt.Sprintf("%s (and %d more errors)", p[0].String(), len(p)-1) + return fmt.Sprintf("%s (and %d more errors)", p[0], len(p)-1) } // These constants control the construction of the ErrorList diff --git a/src/pkg/go/scanner/scanner_test.go b/src/pkg/go/scanner/scanner_test.go index 0c2cbe6dc02..7ed927a49fa 100644 --- a/src/pkg/go/scanner/scanner_test.go +++ b/src/pkg/go/scanner/scanner_test.go @@ -237,7 +237,7 @@ func TestScan(t *testing.T) { } checkPos(t, lit, pos, epos) if tok != e.tok { - t.Errorf("bad token for %q: got %s, expected %s", lit, tok.String(), e.tok.String()) + t.Errorf("bad token for %q: got %s, expected %s", lit, tok, e.tok) } if e.tok.IsLiteral() && lit != e.lit { t.Errorf("bad literal for %q: got %q, expected %q", lit, lit, e.lit) @@ -286,7 +286,7 @@ func checkSemi(t *testing.T, line string, mode uint) { } checkPos(t, line, pos, semiPos) } else { - t.Errorf("bad token for %q: got %s, expected ;", line, tok.String()) + t.Errorf("bad token for %q: got %s, expected ;", line, tok) } } else if tok == token.SEMICOLON { t.Errorf("bad token for %q: got ;, expected no ;", line) @@ -509,7 +509,7 @@ func TestInit(t *testing.T) { s.Scan() // true _, tok, _ := s.Scan() // { if tok != token.LBRACE { - t.Errorf("bad token: got %s, expected %s", tok.String(), token.LBRACE) + t.Errorf("bad token: got %s, expected %s", tok, token.LBRACE) } // 2nd init @@ -521,7 +521,7 @@ func TestInit(t *testing.T) { } _, tok, _ = s.Scan() // go if tok != token.GO { - t.Errorf("bad token: got %s, expected %s", tok.String(), token.GO) + t.Errorf("bad token: got %s, expected %s", tok, token.GO) } if s.ErrorCount != 0 { diff --git a/src/pkg/gob/decode.go b/src/pkg/gob/decode.go index f480087836e..d027d3f1a4b 100644 --- a/src/pkg/gob/decode.go +++ b/src/pkg/gob/decode.go @@ -881,7 +881,7 @@ func (dec *Decoder) decOpFor(wireId typeId, rt reflect.Type, name string, inProg } } if op == nil { - errorf("decode can't handle type %s", rt.String()) + errorf("decode can't handle type %s", rt) } return &op, indir } @@ -1110,7 +1110,7 @@ func (dec *Decoder) compileDec(remoteId typeId, ut *userTypeInfo) (engine *decEn wireStruct = wire.StructT } if wireStruct == nil { - errorf("type mismatch in decoder: want struct type %s; got non-struct", rt.String()) + errorf("type mismatch in decoder: want struct type %s; got non-struct", rt) } engine = new(decEngine) engine.instr = make([]decInstr, len(wireStruct.Field)) diff --git a/src/pkg/gob/encode.go b/src/pkg/gob/encode.go index 6bb54588098..c16443553ce 100644 --- a/src/pkg/gob/encode.go +++ b/src/pkg/gob/encode.go @@ -610,7 +610,7 @@ func (enc *Encoder) encOpFor(rt reflect.Type, inProgress map[reflect.Type]*encOp } } if op == nil { - errorf("can't happen: encode type %s", rt.String()) + errorf("can't happen: encode type %s", rt) } return &op, indir } diff --git a/src/pkg/smtp/smtp_test.go b/src/pkg/smtp/smtp_test.go index c053557d7f4..553d3ae0991 100644 --- a/src/pkg/smtp/smtp_test.go +++ b/src/pkg/smtp/smtp_test.go @@ -37,14 +37,14 @@ testLoop: t.Errorf("#%d got response %s, expected %s", i, resp, test.responses[0]) } if err != nil { - t.Errorf("#%d error: %s", i, err.String()) + t.Errorf("#%d error: %s", i, err) } for j := range test.challenges { challenge := []byte(test.challenges[j]) expected := []byte(test.responses[j+1]) resp, err := test.auth.Next(challenge, true) if err != nil { - t.Errorf("#%d error: %s", i, err.String()) + t.Errorf("#%d error: %s", i, err) continue testLoop } if !bytes.Equal(resp, expected) { @@ -74,13 +74,13 @@ func TestBasic(t *testing.T) { c := &Client{Text: textproto.NewConn(fake)} if err := c.helo(); err != nil { - t.Fatalf("HELO failed: %s", err.String()) + t.Fatalf("HELO failed: %s", err) } if err := c.ehlo(); err == nil { t.Fatalf("Expected first EHLO to fail") } if err := c.ehlo(); err != nil { - t.Fatalf("Second EHLO failed: %s", err.String()) + t.Fatalf("Second EHLO failed: %s", err) } if ok, args := c.Extension("aUtH"); !ok || args != "LOGIN PLAIN" { @@ -105,14 +105,14 @@ func TestBasic(t *testing.T) { c.tls = true c.serverName = "smtp.google.com" if err := c.Auth(PlainAuth("", "user", "pass", "smtp.google.com")); err != nil { - t.Fatalf("AUTH failed: %s", err.String()) + t.Fatalf("AUTH failed: %s", err) } if err := c.Mail("user@gmail.com"); err != nil { - t.Fatalf("MAIL failed: %s", err.String()) + t.Fatalf("MAIL failed: %s", err) } if err := c.Rcpt("golang-nuts@googlegroups.com"); err != nil { - t.Fatalf("RCPT failed: %s", err.String()) + t.Fatalf("RCPT failed: %s", err) } msg := `From: user@gmail.com To: golang-nuts@googlegroups.com @@ -123,17 +123,17 @@ Line 1 Goodbye.` w, err := c.Data() if err != nil { - t.Fatalf("DATA failed: %s", err.String()) + t.Fatalf("DATA failed: %s", err) } if _, err := w.Write([]byte(msg)); err != nil { - t.Fatalf("Data write failed: %s", err.String()) + t.Fatalf("Data write failed: %s", err) } if err := w.Close(); err != nil { - t.Fatalf("Bad data response: %s", err.String()) + t.Fatalf("Bad data response: %s", err) } if err := c.Quit(); err != nil { - t.Fatalf("QUIT failed: %s", err.String()) + t.Fatalf("QUIT failed: %s", err) } bcmdbuf.Flush() diff --git a/src/pkg/strconv/fp_test.go b/src/pkg/strconv/fp_test.go index 3096957f5d3..991d3ac1e43 100644 --- a/src/pkg/strconv/fp_test.go +++ b/src/pkg/strconv/fp_test.go @@ -96,7 +96,7 @@ func myatof32(s string) (f float32, ok bool) { func TestFp(t *testing.T) { f, err := os.Open("testfp.txt") if err != nil { - t.Fatal("testfp: open testfp.txt:", err.String()) + t.Fatal("testfp: open testfp.txt:", err) } defer f.Close()