mirror of
https://github.com/golang/go
synced 2024-11-18 13:04:46 -07:00
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:
parent
4f1c486d35
commit
95c9b7bad1
@ -119,8 +119,8 @@ func asmCheck(pkg *Package) {
|
||||
for lineno, line := range lines {
|
||||
lineno++
|
||||
|
||||
warnf := func(format string, args ...interface{}) {
|
||||
f.Warnf(token.NoPos, "%s:%d: [%s] %s", f.name, lineno, arch, fmt.Sprintf(format, args...))
|
||||
badf := func(format string, args ...interface{}) {
|
||||
f.Badf(token.NoPos, "%s:%d: [%s] %s", f.name, lineno, arch, fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
if arch == "" {
|
||||
@ -147,7 +147,7 @@ func asmCheck(pkg *Package) {
|
||||
if fn != nil {
|
||||
size, _ := strconv.Atoi(m[4])
|
||||
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
|
||||
@ -165,7 +165,7 @@ func asmCheck(pkg *Package) {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -182,13 +182,13 @@ func asmCheck(pkg *Package) {
|
||||
}
|
||||
v = fn.varByOffset[off]
|
||||
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 {
|
||||
warnf("unknown variable %s", name)
|
||||
badf("unknown variable %s", name)
|
||||
}
|
||||
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.
|
||||
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)
|
||||
if m == nil {
|
||||
warnf("cannot find assembly opcode")
|
||||
badf("cannot find assembly opcode")
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
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
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func (f *File) checkAssignStmt(stmt *ast.AssignStmt) {
|
||||
le := f.gofmt(lhs)
|
||||
re := f.gofmt(rhs)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,6 @@ func (f *File) checkAtomicAddAssignment(left ast.Expr, call *ast.CallExpr) {
|
||||
}
|
||||
|
||||
if broken {
|
||||
f.Warn(left.Pos(), "direct assignment to atomic value")
|
||||
f.Bad(left.Pos(), "direct assignment to atomic value")
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ func (f *File) checkUnkeyedLiteral(c *ast.CompositeLit) {
|
||||
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".
|
||||
|
@ -26,7 +26,7 @@ func (f *File) checkCopyLocks(d *ast.FuncDecl) {
|
||||
if d.Recv != nil && len(d.Recv.List) > 0 {
|
||||
expr := d.Recv.List[0].Type
|
||||
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 {
|
||||
expr := field.Type
|
||||
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 {
|
||||
expr := field.Type
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ func (d *deadState) findDead(stmt ast.Stmt) {
|
||||
case *ast.EmptyStmt:
|
||||
// do not warn about unreachable empty statements
|
||||
default:
|
||||
d.f.Warnf(stmt.Pos(), "unreachable code")
|
||||
d.f.Bad(stmt.Pos(), "unreachable code")
|
||||
d.reachable = true // silence error about next statement
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ type formatState struct {
|
||||
// call.Args[formatIndex] is (well, should be) the format argument.
|
||||
func (f *File) checkPrintf(call *ast.CallExpr, name string, formatIndex int) {
|
||||
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
|
||||
}
|
||||
lit := f.pkg.types[call.Args[formatIndex]].Value
|
||||
|
@ -58,7 +58,7 @@ func checkRangeLoop(f *File, n *ast.RangeStmt) {
|
||||
return true
|
||||
}
|
||||
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
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user