1
0
mirror of https://github.com/golang/go synced 2024-09-30 20:28:32 -06:00

all: fix a few issues found by unparam

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í <mvdan@mvdan.cc>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Daniel Martí 2018-02-13 14:24:18 +00:00
parent c0251d31d2
commit 90b807ada4
4 changed files with 13 additions and 13 deletions

View File

@ -113,7 +113,7 @@ func parse(name string, mode present.ParseMode) (*present.Doc, error) {
return nil, err return nil, err
} }
defer f.Close() 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. // dirList scans the given path and writes a directory listing to w.

View File

@ -209,7 +209,7 @@ func (s *sanity) checkInstr(idx int, instr Instruction) {
// enclosing Function or Package. // enclosing Function or Package.
} }
func (s *sanity) checkFinalInstr(idx int, instr Instruction) { func (s *sanity) checkFinalInstr(instr Instruction) {
switch instr := instr.(type) { switch instr := instr.(type) {
case *If: case *If:
if nsuccs := len(s.block.Succs); nsuccs != 2 { if nsuccs := len(s.block.Succs); nsuccs != 2 {
@ -324,7 +324,7 @@ func (s *sanity) checkBlock(b *BasicBlock, index int) {
if j < n-1 { if j < n-1 {
s.checkInstr(j, instr) s.checkInstr(j, instr)
} else { } else {
s.checkFinalInstr(j, instr) s.checkFinalInstr(instr)
} }
// Check Instruction.Operands. // Check Instruction.Operands.

View File

@ -800,8 +800,8 @@ func findImportGoPath(pkgName string, symbols map[string]bool, filename string)
// Fast path for the standard library. // Fast path for the standard library.
// In the common case we hopefully never have to scan the GOPATH, which can // In the common case we hopefully never have to scan the GOPATH, which can
// be slow with moving disks. // be slow with moving disks.
if pkg, rename, ok := findImportStdlib(pkgName, symbols); ok { if pkg, ok := findImportStdlib(pkgName, symbols); ok {
return pkg, rename, nil return pkg, false, nil
} }
if pkgName == "rand" && symbols["Read"] { if pkgName == "rand" && symbols["Read"] {
// Special-case rand.Read. // Special-case rand.Read.
@ -1047,7 +1047,7 @@ func (fn visitFn) Visit(node ast.Node) ast.Visitor {
return fn(node) 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 { for symbol := range symbols {
key := shortPkg + "." + symbol key := shortPkg + "." + symbol
path := stdlib[key] path := stdlib[key]
@ -1055,18 +1055,18 @@ func findImportStdlib(shortPkg string, symbols map[string]bool) (importPath stri
if key == "rand.Read" { if key == "rand.Read" {
continue continue
} }
return "", false, false return "", false
} }
if importPath != "" && importPath != path { if importPath != "" && importPath != path {
// Ambiguous. Symbols pointed to different things. // Ambiguous. Symbols pointed to different things.
return "", false, false return "", false
} }
importPath = path importPath = path
} }
if importPath == "" && shortPkg == "rand" && symbols["Read"] { 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 // fileInDir reports whether the provided file path looks like

View File

@ -1273,12 +1273,12 @@ func TestFindImportStdlib(t *testing.T) {
{"ioutil", []string{"Discard"}, "io/ioutil"}, {"ioutil", []string{"Discard"}, "io/ioutil"},
} }
for _, tt := range tests { for _, tt := range tests {
got, rename, ok := findImportStdlib(tt.pkg, strSet(tt.symbols)) got, ok := findImportStdlib(tt.pkg, strSet(tt.symbols))
if (got != "") != ok { if (got != "") != ok {
t.Error("findImportStdlib return value inconsistent") t.Error("findImportStdlib return value inconsistent")
} }
if got != tt.want || rename { if got != tt.want {
t.Errorf("findImportStdlib(%q, %q) = %q, %t; want %q, false", tt.pkg, tt.symbols, got, rename, tt.want) t.Errorf("findImportStdlib(%q, %q) = %q, want %q", tt.pkg, tt.symbols, got, tt.want)
} }
} }
} }