go.tools/cmd/vet: replace warnings by errors

Over time, a number of modules were added that used Warn instead of Bad
to report problems with the code, but the documentation states that
if there is a problem, the exit code must be 1, not 0. Warn does not set the
exit code and should be used only for internal errors and messages
triggered by the -v flag.

There's nothing substantive here except calling the other function in a few
places.

Fixes golang/go#7017.

LGTM=crawshaw
R=golang-codereviews, crawshaw
CC=golang-codereviews
https://golang.org/cl/71860044
This commit is contained in:
Rob Pike 2014-03-07 15:31:28 +11:00
parent 4f1c486d35
commit 95c9b7bad1
8 changed files with 20 additions and 20 deletions

View File

@ -119,8 +119,8 @@ func asmCheck(pkg *Package) {
for lineno, line := range lines { for lineno, line := range lines {
lineno++ lineno++
warnf := func(format string, args ...interface{}) { badf := func(format string, args ...interface{}) {
f.Warnf(token.NoPos, "%s:%d: [%s] %s", f.name, lineno, arch, fmt.Sprintf(format, args...)) f.Badf(token.NoPos, "%s:%d: [%s] %s", f.name, lineno, arch, fmt.Sprintf(format, args...))
} }
if arch == "" { if arch == "" {
@ -147,7 +147,7 @@ func asmCheck(pkg *Package) {
if fn != nil { if fn != nil {
size, _ := strconv.Atoi(m[4]) size, _ := strconv.Atoi(m[4])
if size != fn.size && (m[2] != "7" && !strings.Contains(m[2], "NOSPLIT") || size != 0) { if size != fn.size && (m[2] != "7" && !strings.Contains(m[2], "NOSPLIT") || size != 0) {
warnf("wrong argument size %d; expected $...-%d", size, fn.size) badf("wrong argument size %d; expected $...-%d", size, fn.size)
} }
} }
continue continue
@ -165,7 +165,7 @@ func asmCheck(pkg *Package) {
} }
for _, m := range asmUnnamedFP.FindAllStringSubmatch(line, -1) { for _, m := range asmUnnamedFP.FindAllStringSubmatch(line, -1) {
warnf("use of unnamed argument %s", m[1]) badf("use of unnamed argument %s", m[1])
} }
for _, m := range asmNamedFP.FindAllStringSubmatch(line, -1) { for _, m := range asmNamedFP.FindAllStringSubmatch(line, -1) {
@ -182,13 +182,13 @@ func asmCheck(pkg *Package) {
} }
v = fn.varByOffset[off] v = fn.varByOffset[off]
if v != nil { if v != nil {
warnf("unknown variable %s; offset %d is %s+%d(FP)", name, off, v.name, v.off) badf("unknown variable %s; offset %d is %s+%d(FP)", name, off, v.name, v.off)
} else { } else {
warnf("unknown variable %s", name) badf("unknown variable %s", name)
} }
continue continue
} }
asmCheckVar(warnf, fn, line, m[0], off, v) asmCheckVar(badf, fn, line, m[0], off, v)
} }
} }
} }
@ -417,10 +417,10 @@ func (f *File) asmParseDecl(decl *ast.FuncDecl) map[string]*asmFunc {
} }
// asmCheckVar checks a single variable reference. // asmCheckVar checks a single variable reference.
func asmCheckVar(warnf func(string, ...interface{}), fn *asmFunc, line, expr string, off int, v *asmVar) { func asmCheckVar(badf func(string, ...interface{}), fn *asmFunc, line, expr string, off int, v *asmVar) {
m := asmOpcode.FindStringSubmatch(line) m := asmOpcode.FindStringSubmatch(line)
if m == nil { if m == nil {
warnf("cannot find assembly opcode") badf("cannot find assembly opcode")
} }
// Determine operand sizes from instruction. // Determine operand sizes from instruction.
@ -510,7 +510,7 @@ func asmCheckVar(warnf func(string, ...interface{}), fn *asmFunc, line, expr str
} }
fmt.Fprintf(&inner, "%s+%d(FP)", vi.name, vi.off) fmt.Fprintf(&inner, "%s+%d(FP)", vi.name, vi.off)
} }
warnf("invalid offset %s; expected %s+%d(FP)%s", expr, v.name, v.off, inner.String()) badf("invalid offset %s; expected %s+%d(FP)%s", expr, v.name, v.off, inner.String())
return return
} }
if kind != 0 && kind != vk { if kind != 0 && kind != vk {
@ -528,6 +528,6 @@ func asmCheckVar(warnf func(string, ...interface{}), fn *asmFunc, line, expr str
fmt.Fprintf(&inner, "%s+%d(FP)", vi.name, vi.off) fmt.Fprintf(&inner, "%s+%d(FP)", vi.name, vi.off)
} }
} }
warnf("invalid %s of %s; %s is %d-byte value%s", op, expr, vt, vk, inner.String()) badf("invalid %s of %s; %s is %d-byte value%s", op, expr, vt, vk, inner.String())
} }
} }

View File

@ -38,7 +38,7 @@ func (f *File) checkAssignStmt(stmt *ast.AssignStmt) {
le := f.gofmt(lhs) le := f.gofmt(lhs)
re := f.gofmt(rhs) re := f.gofmt(rhs)
if le == re { if le == re {
f.Warnf(stmt.Pos(), "self-assignment of %s to %s", re, le) f.Badf(stmt.Pos(), "self-assignment of %s to %s", re, le)
} }
} }
} }

View File

@ -54,6 +54,6 @@ func (f *File) checkAtomicAddAssignment(left ast.Expr, call *ast.CallExpr) {
} }
if broken { if broken {
f.Warn(left.Pos(), "direct assignment to atomic value") f.Bad(left.Pos(), "direct assignment to atomic value")
} }
} }

View File

@ -94,7 +94,7 @@ func (f *File) checkUnkeyedLiteral(c *ast.CompositeLit) {
return return
} }
f.Warn(c.Pos(), typeString+" composite literal uses unkeyed fields") f.Bad(c.Pos(), typeString+" composite literal uses unkeyed fields")
} }
// pkgPath returns the import path "image/png" for the package name "png". // pkgPath returns the import path "image/png" for the package name "png".

View File

@ -26,7 +26,7 @@ func (f *File) checkCopyLocks(d *ast.FuncDecl) {
if d.Recv != nil && len(d.Recv.List) > 0 { if d.Recv != nil && len(d.Recv.List) > 0 {
expr := d.Recv.List[0].Type expr := d.Recv.List[0].Type
if path := lockPath(f.pkg.typesPkg, f.pkg.types[expr].Type); path != nil { if path := lockPath(f.pkg.typesPkg, f.pkg.types[expr].Type); path != nil {
f.Warnf(expr.Pos(), "%s passes Lock by value: %v", d.Name.Name, path) f.Badf(expr.Pos(), "%s passes Lock by value: %v", d.Name.Name, path)
} }
} }
@ -34,7 +34,7 @@ func (f *File) checkCopyLocks(d *ast.FuncDecl) {
for _, field := range d.Type.Params.List { for _, field := range d.Type.Params.List {
expr := field.Type expr := field.Type
if path := lockPath(f.pkg.typesPkg, f.pkg.types[expr].Type); path != nil { if path := lockPath(f.pkg.typesPkg, f.pkg.types[expr].Type); path != nil {
f.Warnf(expr.Pos(), "%s passes Lock by value: %v", d.Name.Name, path) f.Badf(expr.Pos(), "%s passes Lock by value: %v", d.Name.Name, path)
} }
} }
} }
@ -43,7 +43,7 @@ func (f *File) checkCopyLocks(d *ast.FuncDecl) {
for _, field := range d.Type.Results.List { for _, field := range d.Type.Results.List {
expr := field.Type expr := field.Type
if path := lockPath(f.pkg.typesPkg, f.pkg.types[expr].Type); path != nil { if path := lockPath(f.pkg.typesPkg, f.pkg.types[expr].Type); path != nil {
f.Warnf(expr.Pos(), "%s returns Lock by value: %v", d.Name.Name, path) f.Badf(expr.Pos(), "%s returns Lock by value: %v", d.Name.Name, path)
} }
} }
} }

View File

@ -155,7 +155,7 @@ func (d *deadState) findDead(stmt ast.Stmt) {
case *ast.EmptyStmt: case *ast.EmptyStmt:
// do not warn about unreachable empty statements // do not warn about unreachable empty statements
default: default:
d.f.Warnf(stmt.Pos(), "unreachable code") d.f.Bad(stmt.Pos(), "unreachable code")
d.reachable = true // silence error about next statement d.reachable = true // silence error about next statement
} }
} }

View File

@ -82,7 +82,7 @@ type formatState struct {
// call.Args[formatIndex] is (well, should be) the format argument. // call.Args[formatIndex] is (well, should be) the format argument.
func (f *File) checkPrintf(call *ast.CallExpr, name string, formatIndex int) { func (f *File) checkPrintf(call *ast.CallExpr, name string, formatIndex int) {
if formatIndex >= len(call.Args) { if formatIndex >= len(call.Args) {
f.Warn(call.Pos(), "too few arguments in call to", name) f.Bad(call.Pos(), "too few arguments in call to", name)
return return
} }
lit := f.pkg.types[call.Args[formatIndex]].Value lit := f.pkg.types[call.Args[formatIndex]].Value

View File

@ -58,7 +58,7 @@ func checkRangeLoop(f *File, n *ast.RangeStmt) {
return true return true
} }
if key != nil && id.Obj == key.Obj || val != nil && id.Obj == val.Obj { if key != nil && id.Obj == key.Obj || val != nil && id.Obj == val.Obj {
f.Warn(id.Pos(), "range variable", id.Name, "enclosed by function") f.Bad(id.Pos(), "range variable", id.Name, "enclosed by function")
} }
return true return true
}) })