1
0
mirror of https://github.com/golang/go synced 2024-11-24 08:50:14 -07:00

all: update vendored golang.org/x/tools

Now that issue #48124 is resolved, ran the
following commands inside the cmd module:

	go get -d golang.org/x/tools@36045662144327e4475f9d356f49ab32ce730049  # main branch
	go mod tidy
	go mod vendor

For #36905.
Updates #48124.

Change-Id: I9dc736c2c5256f7d9e80fd9c52c6725ecf0b8001
Reviewed-on: https://go-review.googlesource.com/c/go/+/348409
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Trust: Alexander Rakoczy <alex@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Alexander Rakoczy <alex@golang.org>
This commit is contained in:
Dmitri Shuralyov 2021-09-08 09:58:45 -04:00
parent 9295723079
commit 64bdad2011
6 changed files with 60 additions and 18 deletions

View File

@ -10,6 +10,6 @@ require (
golang.org/x/mod v0.5.1-0.20210830214625-1b1db11ec8f4
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
golang.org/x/tools v0.1.6-0.20210809225032-337cebd2c151
golang.org/x/tools v0.1.6-0.20210904010709-360456621443
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
)

View File

@ -16,7 +16,7 @@ golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e h1:XMgFehsDnnLGtjvjOfqWSUzt0
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/tools v0.1.6-0.20210809225032-337cebd2c151 h1:jHjT6WuVKEMzjJgrS1+r1wk54oxwqumUnvtn0QZXyXE=
golang.org/x/tools v0.1.6-0.20210809225032-337cebd2c151/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.6-0.20210904010709-360456621443 h1:7JswviZfk9Rtd4NOelZtuLUdkHdruludwWkfOE6sdZk=
golang.org/x/tools v0.1.6-0.20210904010709-360456621443/go.mod h1:YD9qOF0M9xpSpdWTBbzEl5e/RnCefISl8E5Noe10jFM=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -490,7 +490,7 @@ func printfNameAndKind(pass *analysis.Pass, call *ast.CallExpr) (fn *types.Func,
_, ok = isPrint[strings.ToLower(fn.Name())]
}
if ok {
if fn.Name() == "Errorf" {
if fn.FullName() == "fmt.Errorf" {
kind = KindErrorf
} else if strings.HasSuffix(fn.Name(), "f") {
kind = KindPrintf
@ -590,12 +590,9 @@ func checkPrintf(pass *analysis.Pass, kind Kind, call *ast.CallExpr, fn *types.F
}
if state.verb == 'w' {
switch kind {
case KindNone, KindPrint:
case KindNone, KindPrint, KindPrintf:
pass.Reportf(call.Pos(), "%s does not support error-wrapping directive %%w", state.name)
return
case KindPrintf:
pass.Reportf(call.Pos(), "%s call has error-wrapping directive %%w, which is only supported for functions backed by fmt.Errorf", state.name)
return
}
if anyW {
pass.Reportf(call.Pos(), "%s call has more than one error-wrapping directive %%w", state.name)

View File

@ -119,11 +119,33 @@ func typeIsTestingDotTOrB(expr ast.Expr) (string, bool) {
return varTypeName, ok
}
// goStmtFunc returns the ast.Node of a call expression
// that was invoked as a go statement. Currently, only
// function literals declared in the same function, and
// static calls within the same package are supported.
func goStmtFun(goStmt *ast.GoStmt) ast.Node {
switch goStmt.Call.Fun.(type) {
case *ast.Ident:
id := goStmt.Call.Fun.(*ast.Ident)
// TODO(cuonglm): improve this once golang/go#48141 resolved.
if id.Obj == nil {
break
}
if funDecl, ok := id.Obj.Decl.(ast.Node); ok {
return funDecl
}
case *ast.FuncLit:
return goStmt.Call.Fun
}
return goStmt.Call
}
// checkGoStmt traverses the goroutine and checks for the
// use of the forbidden *testing.(B, T) methods.
func checkGoStmt(pass *analysis.Pass, goStmt *ast.GoStmt) {
fn := goStmtFun(goStmt)
// Otherwise examine the goroutine to check for the forbidden methods.
ast.Inspect(goStmt, func(n ast.Node) bool {
ast.Inspect(fn, func(n ast.Node) bool {
selExpr, ok := n.(*ast.SelectorExpr)
if !ok {
return true
@ -147,7 +169,11 @@ func checkGoStmt(pass *analysis.Pass, goStmt *ast.GoStmt) {
return true
}
if typeName, ok := typeIsTestingDotTOrB(field.Type); ok {
pass.ReportRangef(selExpr, "call to (*%s).%s from a non-test goroutine", typeName, selExpr.Sel)
var fnRange analysis.Range = goStmt
if _, ok := fn.(*ast.FuncLit); ok {
fnRange = selExpr
}
pass.ReportRangef(fnRange, "call to (*%s).%s from a non-test goroutine", typeName, selExpr.Sel)
}
return true
})

View File

@ -78,20 +78,31 @@ func ForNamed(named *types.Named) []*types.TypeName {
return tparamsSlice(named.TParams())
}
func tparamsSlice(tparams *types.TypeParams) []*types.TypeName {
if tparams.Len() == 0 {
func tparamsSlice(tparams *types.TParamList) []*types.TypeName {
length := tparams.Len()
if length == 0 {
return nil
}
result := make([]*types.TypeName, tparams.Len())
for i := 0; i < tparams.Len(); i++ {
result[i] = tparams.At(i)
result := make([]*types.TypeName, length)
for i := 0; i < length; i++ {
result[i] = tparams.At(i).Obj()
}
return result
}
// NamedTArgs extracts the (possibly empty) type argument list from named.
func NamedTArgs(named *types.Named) []types.Type {
return named.TArgs()
targs := named.TArgs()
numArgs := targs.Len()
typs := make([]types.Type, numArgs)
for i := 0; i < numArgs; i++ {
typs[i] = targs.At(i)
}
return typs
}
// InitInferred initializes info to record inferred type information.
@ -111,5 +122,13 @@ func GetInferred(info *types.Info, e ast.Expr) ([]types.Type, *types.Signature)
return nil, nil
}
inf := info.Inferred[e]
return inf.TArgs, inf.Sig
length := inf.TArgs.Len()
typs := make([]types.Type, length)
for i := 0; i < length; i++ {
typs[i] = inf.TArgs.At(i)
}
return typs, inf.Sig
}

View File

@ -48,7 +48,7 @@ golang.org/x/sys/windows
# golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
## explicit; go 1.17
golang.org/x/term
# golang.org/x/tools v0.1.6-0.20210809225032-337cebd2c151
# golang.org/x/tools v0.1.6-0.20210904010709-360456621443
## explicit; go 1.17
golang.org/x/tools/cover
golang.org/x/tools/go/analysis