all: fix some staticcheck errors
Updates golang/go#35718
Change-Id: I10bfd5421cd44bb58b8bcaa6e9205040c25f51be
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208257
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/go/analysis/doc.go b/go/analysis/doc.go
index 8fa4a85..ea56b72 100644
--- a/go/analysis/doc.go
+++ b/go/analysis/doc.go
@@ -1,6 +1,6 @@
/*
-The analysis package defines the interface between a modular static
+Package analysis defines the interface between a modular static
analysis and an analysis driver program.
diff --git a/go/cfg/cfg.go b/go/cfg/cfg.go
index b075034..3ebc65f 100644
--- a/go/cfg/cfg.go
+++ b/go/cfg/cfg.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// This package constructs a simple control-flow graph (CFG) of the
+// Package cfg constructs a simple control-flow graph (CFG) of the
// statements and expressions within a single function.
//
// Use cfg.New to construct the CFG for a function body.
diff --git a/go/internal/cgo/cgo.go b/go/internal/cgo/cgo.go
index 0f652ea..5db8b30 100644
--- a/go/internal/cgo/cgo.go
+++ b/go/internal/cgo/cgo.go
@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package cgo
-
-// This file handles cgo preprocessing of files containing `import "C"`.
+// Package cgo handles cgo preprocessing of files containing `import "C"`.
//
// DESIGN
//
@@ -51,6 +49,8 @@
// its handling of function calls, analogous to the treatment of map
// lookups in which y=m[k] and y,ok=m[k] are both legal.
+package cgo
+
import (
"fmt"
"go/ast"
diff --git a/go/internal/gccgoimporter/ar.go b/go/internal/gccgoimporter/ar.go
index 7b25abb..b8869c3 100644
--- a/go/internal/gccgoimporter/ar.go
+++ b/go/internal/gccgoimporter/ar.go
@@ -84,7 +84,7 @@
}
off += arHdrSize
- if bytes.Compare(hdrBuf[arFmagOff:arFmagOff+arFmagSize], []byte(arfmag)) != 0 {
+ if !bytes.Equal(hdrBuf[arFmagOff:arFmagOff+arFmagSize], []byte(arfmag)) {
return nil, fmt.Errorf("archive header format header (%q)", hdrBuf[:])
}
@@ -94,7 +94,7 @@
}
fn := hdrBuf[arNameOff : arNameOff+arNameSize]
- if fn[0] == '/' && (fn[1] == ' ' || fn[1] == '/' || bytes.Compare(fn[:8], []byte("/SYM64/ ")) == 0) {
+ if fn[0] == '/' && (fn[1] == ' ' || fn[1] == '/' || bytes.Equal(fn[:8], []byte("/SYM64/ "))) {
// Archive symbol table or extended name table,
// which we don't care about.
} else {
diff --git a/go/internal/gccgoimporter/parser.go b/go/internal/gccgoimporter/parser.go
index 2a86734..29e8c60 100644
--- a/go/internal/gccgoimporter/parser.go
+++ b/go/internal/gccgoimporter/parser.go
@@ -1025,7 +1025,7 @@
func (p *parser) parseTypes(pkg *types.Package) {
maxp1 := p.parseInt()
exportedp1 := p.parseInt()
- p.typeList = make([]types.Type, maxp1, maxp1)
+ p.typeList = make([]types.Type, maxp1)
type typeOffset struct {
offset int
diff --git a/go/internal/gcimporter/gcimporter.go b/go/internal/gcimporter/gcimporter.go
index 9cf1866..1e12965 100644
--- a/go/internal/gcimporter/gcimporter.go
+++ b/go/internal/gcimporter/gcimporter.go
@@ -344,7 +344,7 @@
// PackageId = string_lit .
//
-func (p *parser) parsePackageId() string {
+func (p *parser) parsePackageID() string {
id, err := strconv.Unquote(p.expect(scanner.String))
if err != nil {
p.error(err)
@@ -384,7 +384,7 @@
//
func (p *parser) parseQualifiedName() (id, name string) {
p.expect('@')
- id = p.parsePackageId()
+ id = p.parsePackageID()
p.expect('.')
// Per rev f280b8a485fd (10/2/2013), qualified names may be used for anonymous fields.
if p.tok == '?' {
@@ -696,7 +696,7 @@
// Complete requires the type's embedded interfaces to be fully defined,
// but we do not define any
- return types.NewInterface(methods, nil).Complete()
+ return types.NewInterfaceType(methods, nil).Complete()
}
// ChanType = ( "chan" [ "<-" ] | "<-" "chan" ) Type .
@@ -785,7 +785,7 @@
func (p *parser) parseImportDecl() {
p.expectKeyword("import")
name := p.parsePackageName()
- p.getPkg(p.parsePackageId(), name)
+ p.getPkg(p.parsePackageID(), name)
}
// int_lit = [ "+" | "-" ] { "0" ... "9" } .
diff --git a/go/pointer/api.go b/go/pointer/api.go
index 3c5c6dc..2a13a67 100644
--- a/go/pointer/api.go
+++ b/go/pointer/api.go
@@ -230,11 +230,11 @@
if s.pts != nil {
var space [50]int
for _, x := range s.pts.AppendTo(space[:0]) {
- ifaceObjId := nodeid(x)
- if !s.a.isTaggedObject(ifaceObjId) {
+ ifaceObjID := nodeid(x)
+ if !s.a.isTaggedObject(ifaceObjID) {
continue // !CanHaveDynamicTypes(tDyn)
}
- tDyn, v, indirect := s.a.taggedValue(ifaceObjId)
+ tDyn, v, indirect := s.a.taggedValue(ifaceObjID)
if indirect {
panic("indirect tagged object") // implement later
}
@@ -251,13 +251,13 @@
// Intersects reports whether this points-to set and the
// argument points-to set contain common members.
-func (x PointsToSet) Intersects(y PointsToSet) bool {
- if x.pts == nil || y.pts == nil {
+func (s PointsToSet) Intersects(y PointsToSet) bool {
+ if s.pts == nil || y.pts == nil {
return false
}
// This takes Θ(|x|+|y|) time.
var z intsets.Sparse
- z.Intersection(&x.pts.Sparse, &y.pts.Sparse)
+ z.Intersection(&s.pts.Sparse, &y.pts.Sparse)
return !z.IsEmpty()
}
diff --git a/go/pointer/gen.go b/go/pointer/gen.go
index f2a5171..5d2d621 100644
--- a/go/pointer/gen.go
+++ b/go/pointer/gen.go
@@ -20,7 +20,7 @@
)
var (
- tEface = types.NewInterface(nil, nil).Complete()
+ tEface = types.NewInterfaceType(nil, nil).Complete()
tInvalid = types.Typ[types.Invalid]
tUnsafePtr = types.Typ[types.UnsafePointer]
)
@@ -503,8 +503,7 @@
y := instr.Call.Args[1]
tArray := sliceToArray(instr.Call.Args[0].Type())
- var w nodeid
- w = a.nextNode()
+ w := a.nextNode()
a.addNodes(tArray, "append")
a.endObject(w, cgn, instr)
diff --git a/go/pointer/hvn.go b/go/pointer/hvn.go
index 192e405..52fd479 100644
--- a/go/pointer/hvn.go
+++ b/go/pointer/hvn.go
@@ -391,10 +391,9 @@
if debugHVNVerbose && h.log != nil {
fmt.Fprintf(h.log, "\to%d --> o%d\n", h.ref(odst), osrc)
}
- } else {
- // We don't interpret store-with-offset.
- // See discussion of soundness at markIndirectNodes.
}
+ // We don't interpret store-with-offset.
+ // See discussion of soundness at markIndirectNodes.
}
// dst = &src.offset
@@ -785,11 +784,11 @@
assert(peLabels.Len() == 1, "PE class is not a singleton")
label := peLabel(peLabels.Min())
- canonId := canon[label]
- if canonId == nodeid(h.N) {
+ canonID := canon[label]
+ if canonID == nodeid(h.N) {
// id becomes the representative of the PE label.
- canonId = id
- canon[label] = canonId
+ canonID = id
+ canon[label] = canonID
if h.a.log != nil {
fmt.Fprintf(h.a.log, "\tpts(n%d) is canonical : \t(%s)\n",
@@ -798,8 +797,8 @@
} else {
// Link the solver states for the two nodes.
- assert(h.a.nodes[canonId].solve != nil, "missing solver state")
- h.a.nodes[id].solve = h.a.nodes[canonId].solve
+ assert(h.a.nodes[canonID].solve != nil, "missing solver state")
+ h.a.nodes[id].solve = h.a.nodes[canonID].solve
if h.a.log != nil {
// TODO(adonovan): debug: reorganize the log so it prints
@@ -807,11 +806,11 @@
// pe y = x1, ..., xn
// for each canonical y. Requires allocation.
fmt.Fprintf(h.a.log, "\tpts(n%d) = pts(n%d) : %s\n",
- id, canonId, h.a.nodes[id].typ)
+ id, canonID, h.a.nodes[id].typ)
}
}
- mapping[id] = canonId
+ mapping[id] = canonID
}
// Renumber the constraints, eliminate duplicates, and eliminate
diff --git a/go/pointer/opt.go b/go/pointer/opt.go
index 81f80aa..6defea1 100644
--- a/go/pointer/opt.go
+++ b/go/pointer/opt.go
@@ -34,8 +34,8 @@
}
N := nodeid(len(a.nodes))
- newNodes := make([]*node, N, N)
- renumbering := make([]nodeid, N, N) // maps old to new
+ newNodes := make([]*node, N)
+ renumbering := make([]nodeid, N) // maps old to new
var i, j nodeid
diff --git a/go/pointer/util.go b/go/pointer/util.go
index 683fddd..986dd09 100644
--- a/go/pointer/util.go
+++ b/go/pointer/util.go
@@ -277,8 +277,8 @@
return ns.Sparse.Insert(int(n))
}
-func (x *nodeset) addAll(y *nodeset) bool {
- return x.UnionWith(&y.Sparse)
+func (ns *nodeset) addAll(y *nodeset) bool {
+ return ns.UnionWith(&y.Sparse)
}
// Profiling & debugging -------------------------------------------------------
diff --git a/go/ssa/builder.go b/go/ssa/builder.go
index a13a884..155c1e0 100644
--- a/go/ssa/builder.go
+++ b/go/ssa/builder.go
@@ -58,7 +58,7 @@
tString = types.Typ[types.String]
tUntypedNil = types.Typ[types.UntypedNil]
tRangeIter = &opaqueType{nil, "iter"} // the type of all "range" iterators
- tEface = types.NewInterface(nil, nil).Complete()
+ tEface = types.NewInterfaceType(nil, nil).Complete()
// SSA Value constants.
vZero = intConst(0)
diff --git a/go/ssa/dom.go b/go/ssa/dom.go
index 12ef430..822fe97 100644
--- a/go/ssa/dom.go
+++ b/go/ssa/dom.go
@@ -53,7 +53,7 @@
//
func (f *Function) DomPreorder() []*BasicBlock {
n := len(f.Blocks)
- order := make(byDomPreorder, n, n)
+ order := make(byDomPreorder, n)
copy(order, f.Blocks)
sort.Sort(order)
return order
@@ -123,7 +123,7 @@
n := len(f.Blocks)
// Allocate space for 5 contiguous [n]*BasicBlock arrays:
// sdom, parent, ancestor, preorder, buckets.
- space := make([]*BasicBlock, 5*n, 5*n)
+ space := make([]*BasicBlock, 5*n)
lt := ltState{
sdom: space[0:n],
parent: space[n : 2*n],
diff --git a/go/types/typeutil/callee_test.go b/go/types/typeutil/callee_test.go
index a0d107d..272e1eb 100644
--- a/go/types/typeutil/callee_test.go
+++ b/go/types/typeutil/callee_test.go
@@ -63,7 +63,7 @@
Uses: make(map[*ast.Ident]types.Object),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
}
- cfg := &types.Config{Importer: importer.For("source", nil)}
+ cfg := &types.Config{Importer: importer.ForCompiler(fset, "source", nil)}
if _, err := cfg.Check("p", fset, []*ast.File{f}, info); err != nil {
t.Fatal(err)
}
diff --git a/go/types/typeutil/map_test.go b/go/types/typeutil/map_test.go
index 34facbe..d4b0f63 100644
--- a/go/types/typeutil/map_test.go
+++ b/go/types/typeutil/map_test.go
@@ -47,7 +47,7 @@
tmap.At(tPStr1)
tmap.Delete(tPStr1)
tmap.KeysString()
- tmap.String()
+ _ = tmap.String()
tmap = new(typeutil.Map)