From 90b807ada4cc7ab5d1409d637b1f3beb5a776be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 13 Feb 2018 14:24:18 +0000 Subject: [PATCH] all: fix a few issues found by unparam MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In cmd/present, a mode was being passed to the function parse, but it wasn't actually being used. Use it. In go/ssa, checkFinalInstr received an idx integer but it doesn't actually need it. Get rid of it. Lastly, in imports, findImportStdlib always returned rename==false. Get rid of that result parameter. Change-Id: I719006b69ee80a3ef4b0ea24c1c206016a7e304b Reviewed-on: https://go-review.googlesource.com/93596 Run-TryBot: Daniel Martí Run-TryBot: Brad Fitzpatrick Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- cmd/present/dir.go | 2 +- go/ssa/sanity.go | 4 ++-- imports/fix.go | 14 +++++++------- imports/fix_test.go | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/present/dir.go b/cmd/present/dir.go index 02763513..19aec87e 100644 --- a/cmd/present/dir.go +++ b/cmd/present/dir.go @@ -113,7 +113,7 @@ func parse(name string, mode present.ParseMode) (*present.Doc, error) { return nil, err } defer f.Close() - return present.Parse(f, name, 0) + return present.Parse(f, name, mode) } // dirList scans the given path and writes a directory listing to w. diff --git a/go/ssa/sanity.go b/go/ssa/sanity.go index b15ad9fb..0d13beb9 100644 --- a/go/ssa/sanity.go +++ b/go/ssa/sanity.go @@ -209,7 +209,7 @@ func (s *sanity) checkInstr(idx int, instr Instruction) { // enclosing Function or Package. } -func (s *sanity) checkFinalInstr(idx int, instr Instruction) { +func (s *sanity) checkFinalInstr(instr Instruction) { switch instr := instr.(type) { case *If: if nsuccs := len(s.block.Succs); nsuccs != 2 { @@ -324,7 +324,7 @@ func (s *sanity) checkBlock(b *BasicBlock, index int) { if j < n-1 { s.checkInstr(j, instr) } else { - s.checkFinalInstr(j, instr) + s.checkFinalInstr(instr) } // Check Instruction.Operands. diff --git a/imports/fix.go b/imports/fix.go index 8dbbd27a..de660879 100644 --- a/imports/fix.go +++ b/imports/fix.go @@ -800,8 +800,8 @@ func findImportGoPath(pkgName string, symbols map[string]bool, filename string) // Fast path for the standard library. // In the common case we hopefully never have to scan the GOPATH, which can // be slow with moving disks. - if pkg, rename, ok := findImportStdlib(pkgName, symbols); ok { - return pkg, rename, nil + if pkg, ok := findImportStdlib(pkgName, symbols); ok { + return pkg, false, nil } if pkgName == "rand" && symbols["Read"] { // Special-case rand.Read. @@ -1047,7 +1047,7 @@ func (fn visitFn) Visit(node ast.Node) ast.Visitor { return fn(node) } -func findImportStdlib(shortPkg string, symbols map[string]bool) (importPath string, rename, ok bool) { +func findImportStdlib(shortPkg string, symbols map[string]bool) (importPath string, ok bool) { for symbol := range symbols { key := shortPkg + "." + symbol path := stdlib[key] @@ -1055,18 +1055,18 @@ func findImportStdlib(shortPkg string, symbols map[string]bool) (importPath stri if key == "rand.Read" { continue } - return "", false, false + return "", false } if importPath != "" && importPath != path { // Ambiguous. Symbols pointed to different things. - return "", false, false + return "", false } importPath = path } if importPath == "" && shortPkg == "rand" && symbols["Read"] { - return "crypto/rand", false, true + return "crypto/rand", true } - return importPath, false, importPath != "" + return importPath, importPath != "" } // fileInDir reports whether the provided file path looks like diff --git a/imports/fix_test.go b/imports/fix_test.go index bb5fcb9e..bc18772c 100644 --- a/imports/fix_test.go +++ b/imports/fix_test.go @@ -1273,12 +1273,12 @@ func TestFindImportStdlib(t *testing.T) { {"ioutil", []string{"Discard"}, "io/ioutil"}, } for _, tt := range tests { - got, rename, ok := findImportStdlib(tt.pkg, strSet(tt.symbols)) + got, ok := findImportStdlib(tt.pkg, strSet(tt.symbols)) if (got != "") != ok { t.Error("findImportStdlib return value inconsistent") } - if got != tt.want || rename { - t.Errorf("findImportStdlib(%q, %q) = %q, %t; want %q, false", tt.pkg, tt.symbols, got, rename, tt.want) + if got != tt.want { + t.Errorf("findImportStdlib(%q, %q) = %q, want %q", tt.pkg, tt.symbols, got, tt.want) } } }