1
0
mirror of https://github.com/golang/go synced 2024-11-23 07:20:06 -07:00

cmd/vendor: update to golang.org/x/tools@139d099f

Mainly to pull the fix for the regression in #28792.

Change-Id: If71ae783fd9a9e3935186b49fdf501ba098235a2
Reviewed-on: https://go-review.googlesource.com/c/150161
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Daniel Martí 2018-11-19 14:18:04 +00:00
parent bc43889566
commit 3c92bdc7db
5 changed files with 87 additions and 78 deletions

View File

@ -16,7 +16,7 @@ import (
"golang.org/x/tools/go/ast/inspector"
)
const Doc = `checked for unkeyed composite literals
const Doc = `check for unkeyed composite literals
This analyzer reports a diagnostic for composite literals of struct
types imported from another package that do not use the field-keyed

View File

@ -93,7 +93,9 @@ func runFunc(pass *analysis.Pass, node ast.Node) {
// ctx, cancel = context.WithCancel(...)
// var ctx, cancel = context.WithCancel(...)
//
if isContextWithCancel(pass.TypesInfo, n) && isCall(stack[len(stack)-2]) {
if !isContextWithCancel(pass.TypesInfo, n) || !isCall(stack[len(stack)-2]) {
return true
}
var id *ast.Ident // id of cancel var
stmt := stack[len(stack)-3]
switch stmt := stmt.(type) {
@ -117,8 +119,6 @@ func runFunc(pass *analysis.Pass, node ast.Node) {
cancelvars[v] = stmt
}
}
}
return true
})
@ -179,9 +179,15 @@ func hasImport(pkg *types.Package, path string) bool {
// isContextWithCancel reports whether n is one of the qualified identifiers
// context.With{Cancel,Timeout,Deadline}.
func isContextWithCancel(info *types.Info, n ast.Node) bool {
if sel, ok := n.(*ast.SelectorExpr); ok {
sel, ok := n.(*ast.SelectorExpr)
if !ok {
return false
}
switch sel.Sel.Name {
case "WithCancel", "WithTimeout", "WithDeadline":
default:
return false
}
if x, ok := sel.X.(*ast.Ident); ok {
if pkgname, ok := info.Uses[x].(*types.PkgName); ok {
return pkgname.Imported().Path() == contextPackage
@ -190,8 +196,6 @@ func isContextWithCancel(info *types.Info, n ast.Node) bool {
// Just check the local package name (heuristic).
return x.Name == "context"
}
}
}
return false
}
@ -270,7 +274,9 @@ outer:
var search func(blocks []*cfg.Block) *ast.ReturnStmt
search = func(blocks []*cfg.Block) *ast.ReturnStmt {
for _, b := range blocks {
if !seen[b] {
if seen[b] {
continue
}
seen[b] = true
// Prune the search if the block uses v.
@ -294,7 +300,6 @@ outer:
return ret
}
}
}
return nil
}
return search(defblock.Succs)

View File

@ -131,7 +131,7 @@ func canonicalMethod(pass *analysis.Pass, id *ast.Ident) {
expectFmt += " (" + argjoin(expect.results) + ")"
}
actual := types.TypeString(sign, (*types.Package).Name)
actual := typeString(sign)
actual = strings.TrimPrefix(actual, "func")
actual = id.Name + actual
@ -139,6 +139,10 @@ func canonicalMethod(pass *analysis.Pass, id *ast.Ident) {
}
}
func typeString(typ types.Type) string {
return types.TypeString(typ, (*types.Package).Name)
}
func argjoin(x []string) string {
y := make([]string, len(x))
for i, s := range x {
@ -178,5 +182,5 @@ func matchParamType(fset *token.FileSet, pkg *types.Package, expect string, actu
}
// Overkill but easy.
return actual.String() == expect
return typeString(actual) == expect
}

View File

@ -62,8 +62,9 @@ func isSafeUintptr(info *types.Info, x ast.Expr) bool {
return isSafeUintptr(info, x.X)
case *ast.SelectorExpr:
switch x.Sel.Name {
case "Data":
if x.Sel.Name != "Data" {
break
}
// reflect.SliceHeader and reflect.StringHeader are okay,
// but only if they are pointing at a real slice or string.
// It's not okay to do:
@ -86,7 +87,6 @@ func isSafeUintptr(info *types.Info, x ast.Expr) bool {
}
}
}
}
case *ast.CallExpr:
switch len(x.Args) {