]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.12] cmd/vendor/golang.org/x/tools/go/analysis: update from releas...
authorRuss Cox <rsc@golang.org>
Tue, 30 Apr 2019 17:24:34 +0000 (13:24 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 1 May 2019 15:18:03 +0000 (15:18 +0000)
$ ./update-xtools.sh
Copied /Users/rsc/src/golang.org/x/tools@aa829657 to .
$ cd ~/src/golang.org/x/tools
$ git log -n1 aa829657
commit aa82965741a9fecd12b026fbb3d3c6ed3231b8f8 (HEAD -> release-branch.go1.12, origin/release-branch.go1.12)
Author:     Daniel Martí <mvdan@mvdan.cc>
AuthorDate: Fri Mar 1 11:00:19 2019 +0000
Commit:     Brad Fitzpatrick <bradfitz@golang.org>
CommitDate: Wed Mar 13 21:06:03 2019 +0000
...
$

Picks up cmd/vet fixes that have been inadvertently missed in point releases so far.

Fixes #30399.
Fixes #30465.

Change-Id: Ibcfaac51d134205b986b32f857d54006b19c896a
Reviewed-on: https://go-review.googlesource.com/c/go/+/174519
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
12 files changed:
src/cmd/vendor/golang.org/x/tools/go/analysis/analysis.go
src/cmd/vendor/golang.org/x/tools/go/analysis/doc.go
src/cmd/vendor/golang.org/x/tools/go/analysis/passes/asmdecl/asmdecl.go
src/cmd/vendor/golang.org/x/tools/go/analysis/passes/cgocall/cgocall.go
src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/composite.go
src/cmd/vendor/golang.org/x/tools/go/analysis/passes/inspect/inspect.go
src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/printf.go
src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/types.go
src/cmd/vendor/golang.org/x/tools/go/analysis/passes/shift/shift.go
src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go
src/cmd/vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker.go
src/cmd/vendor/golang.org/x/tools/go/ast/inspector/inspector.go

index 21baa02a8de38b3eb7faf35ba56e281f8ab412cd..4d8a6e5e7d9cba2565424767c0200140bec0a9b8 100644 (file)
@@ -87,6 +87,7 @@ type Pass struct {
        OtherFiles []string       // names of non-Go files of this package
        Pkg        *types.Package // type information about the package
        TypesInfo  *types.Info    // type information about the syntax trees
+       TypesSizes types.Sizes    // function for computing sizes of types
 
        // Report reports a Diagnostic, a finding about a specific location
        // in the analyzed source code such as a potential mistake.
index f925849ab508972b026d7c4f11e3ac660dc45136..2d44b0458a9a2b8b66008e17c9cc6d9cbe5f945c 100644 (file)
@@ -246,7 +246,7 @@ An Analyzer that uses facts must declare their types:
 
        var Analyzer = &analysis.Analyzer{
                Name:       "printf",
-               FactTypes: []reflect.Type{reflect.TypeOf(new(isWrapper))},
+               FactTypes: []analysis.Fact{new(isWrapper)},
                ...
        }
 
index dce1ef7bd5e6d0626cf441353db71329fc7712d8..6403d7783a2b3b3626976b2dc37298369bf76f0e 100644 (file)
@@ -114,7 +114,8 @@ func init() {
                        // library we cannot assume types.SizesFor is consistent with arches.
                        // For now, assume 64-bit norms and print a warning.
                        // But this warning should really be deferred until we attempt to use
-                       // arch, which is very unlikely.
+                       // arch, which is very unlikely. Better would be
+                       // to defer size computation until we have Pass.TypesSizes.
                        arch.sizes = types.SizesFor("gc", "amd64")
                        log.Printf("unknown architecture %s", arch.name)
                }
index 993f1ce3c4b4ace9bd2d1da945bf8f5f8cda6593..1e4fac859546e93e292a40ae53e021a1dcaadfa2 100644 (file)
@@ -9,7 +9,6 @@ package cgocall
 import (
        "fmt"
        "go/ast"
-       "go/build"
        "go/format"
        "go/parser"
        "go/token"
@@ -45,7 +44,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
                return nil, nil // doesn't use cgo
        }
 
-       cgofiles, info, err := typeCheckCgoSourceFiles(pass.Fset, pass.Pkg, pass.Files, pass.TypesInfo)
+       cgofiles, info, err := typeCheckCgoSourceFiles(pass.Fset, pass.Pkg, pass.Files, pass.TypesInfo, pass.TypesSizes)
        if err != nil {
                return nil, err
        }
@@ -171,7 +170,7 @@ func checkCgo(fset *token.FileSet, f *ast.File, info *types.Info, reportf func(t
 // limited ourselves here to preserving function bodies and initializer
 // expressions since that is all that the cgocall analyzer needs.
 //
-func typeCheckCgoSourceFiles(fset *token.FileSet, pkg *types.Package, files []*ast.File, info *types.Info) ([]*ast.File, *types.Info, error) {
+func typeCheckCgoSourceFiles(fset *token.FileSet, pkg *types.Package, files []*ast.File, info *types.Info, sizes types.Sizes) ([]*ast.File, *types.Info, error) {
        const thispkg = "·this·"
 
        // Which files are cgo files?
@@ -269,8 +268,7 @@ func typeCheckCgoSourceFiles(fset *token.FileSet, pkg *types.Package, files []*a
                Importer: importerFunc(func(path string) (*types.Package, error) {
                        return importMap[path], nil
                }),
-               // TODO(adonovan): Sizes should probably be provided by analysis.Pass.
-               Sizes: types.SizesFor("gc", build.Default.GOARCH),
+               Sizes: sizes,
                Error: func(error) {}, // ignore errors (e.g. unused import)
        }
 
index 9cca7781d004429f5c2610b47fc065c71220426e..2abe7c6d51e803a5bc927d0581d3340d37254f16 100644 (file)
@@ -21,7 +21,16 @@ 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
 syntax. Such literals are fragile because the addition of a new field
-(even if unexported) to the struct will cause compilation to fail.`
+(even if unexported) to the struct will cause compilation to fail.
+
+As an example,
+
+       err = &net.DNSConfigError{err}
+
+should be replaced by:
+
+       err = &net.DNSConfigError{Err: err}
+`
 
 var Analyzer = &analysis.Analyzer{
        Name:             "composites",
index bd06549984a2ad8b78ca45a33e44a43de7000236..8213f633135934088b7ec2711ecf7edb600b24b8 100644 (file)
@@ -8,7 +8,11 @@
 //
 // Example of use in another analysis:
 //
-//     import "golang.org/x/tools/go/analysis/passes/inspect"
+//     import (
+//             "golang.org/x/tools/go/analysis"
+//             "golang.org/x/tools/go/analysis/passes/inspect"
+//             "golang.org/x/tools/go/ast/inspector"
+//     )
 //
 //     var Analyzer = &analysis.Analyzer{
 //             ...
index c0265aafeee7ff132b6b37e366a088a97cd884e3..b73ff5e0c3c690867d39c8c195021b0ace352344 100644 (file)
@@ -453,15 +453,23 @@ func printfNameAndKind(pass *analysis.Pass, call *ast.CallExpr) (fn *types.Func,
 }
 
 // isFormatter reports whether t satisfies fmt.Formatter.
-// Unlike fmt.Stringer, it's impossible to satisfy fmt.Formatter without importing fmt.
-func isFormatter(pass *analysis.Pass, t types.Type) bool {
-       for _, imp := range pass.Pkg.Imports() {
-               if imp.Path() == "fmt" {
-                       formatter := imp.Scope().Lookup("Formatter").Type().Underlying().(*types.Interface)
-                       return types.Implements(t, formatter)
-               }
+// The only interface method to look for is "Format(State, rune)".
+func isFormatter(typ types.Type) bool {
+       obj, _, _ := types.LookupFieldOrMethod(typ, false, nil, "Format")
+       fn, ok := obj.(*types.Func)
+       if !ok {
+               return false
        }
-       return false
+       sig := fn.Type().(*types.Signature)
+       return sig.Params().Len() == 2 &&
+               sig.Results().Len() == 0 &&
+               isNamed(sig.Params().At(0).Type(), "fmt", "State") &&
+               types.Identical(sig.Params().At(1).Type(), types.Typ[types.Rune])
+}
+
+func isNamed(T types.Type, pkgpath, name string) bool {
+       named, ok := T.(*types.Named)
+       return ok && named.Obj().Pkg().Path() == pkgpath && named.Obj().Name() == name
 }
 
 // formatState holds the parsed representation of a printf directive such as "%3.*[4]d".
@@ -753,7 +761,7 @@ func okPrintfArg(pass *analysis.Pass, call *ast.CallExpr, state *formatState) (o
        formatter := false
        if state.argNum < len(call.Args) {
                if tv, ok := pass.TypesInfo.Types[call.Args[state.argNum]]; ok {
-                       formatter = isFormatter(pass, tv.Type)
+                       formatter = isFormatter(tv.Type)
                }
        }
 
@@ -831,7 +839,7 @@ func recursiveStringer(pass *analysis.Pass, e ast.Expr) bool {
        typ := pass.TypesInfo.Types[e].Type
 
        // It's unlikely to be a recursive stringer if it has a Format method.
-       if isFormatter(pass, typ) {
+       if isFormatter(typ) {
                return false
        }
 
index e8810464cd420255836ae2a26141806d0313336d..12286fd5df554a00a6d6019915ff04a304a2fad6 100644 (file)
@@ -2,7 +2,6 @@ package printf
 
 import (
        "go/ast"
-       "go/build"
        "go/types"
 
        "golang.org/x/tools/go/analysis"
@@ -39,7 +38,7 @@ func matchArgTypeInternal(pass *analysis.Pass, t printfArgType, typ types.Type,
                }
        }
        // If the type implements fmt.Formatter, we have nothing to check.
-       if isFormatter(pass, typ) {
+       if isFormatter(typ) {
                return true
        }
        // If we can use a string, might arg (dynamically) implement the Stringer or Error interface?
@@ -235,5 +234,3 @@ func matchStructArgType(pass *analysis.Pass, t printfArgType, typ *types.Struct,
        }
        return true
 }
-
-var archSizes = types.SizesFor("gc", build.Default.GOARCH)
index 56b150b2b132cd65b774a46b25d7bde94a8858be..39f54573c9fd644c8279e89aa67f77b9b8129efb 100644 (file)
@@ -12,10 +12,8 @@ package shift
 
 import (
        "go/ast"
-       "go/build"
        "go/constant"
        "go/token"
-       "go/types"
 
        "golang.org/x/tools/go/analysis"
        "golang.org/x/tools/go/analysis/passes/inspect"
@@ -93,36 +91,9 @@ func checkLongShift(pass *analysis.Pass, node ast.Node, x, y ast.Expr) {
        if t == nil {
                return
        }
-       b, ok := t.Underlying().(*types.Basic)
-       if !ok {
-               return
-       }
-       var size int64
-       switch b.Kind() {
-       case types.Uint8, types.Int8:
-               size = 8
-       case types.Uint16, types.Int16:
-               size = 16
-       case types.Uint32, types.Int32:
-               size = 32
-       case types.Uint64, types.Int64:
-               size = 64
-       case types.Int, types.Uint:
-               size = uintBitSize
-       case types.Uintptr:
-               size = uintptrBitSize
-       default:
-               return
-       }
+       size := 8 * pass.TypesSizes.Sizeof(t)
        if amt >= size {
                ident := analysisutil.Format(pass.Fset, x)
                pass.Reportf(node.Pos(), "%s (%d bits) too small for shift of %d", ident, size, amt)
        }
 }
-
-var (
-       uintBitSize    = 8 * archSizes.Sizeof(types.Typ[types.Uint])
-       uintptrBitSize = 8 * archSizes.Sizeof(types.Typ[types.Uintptr])
-)
-
-var archSizes = types.SizesFor("gc", build.Default.GOARCH)
index 2b67c376bab8b9703d1b62d9a75f1601c8ec6d34..5b27208e9185631f5049811f5b6eda781b26b6d9 100644 (file)
@@ -96,6 +96,11 @@ func checkTagDuplicates(pass *analysis.Pass, tag, key string, nearest, field *ty
        }
        if val == "" || val[0] == ',' {
                if field.Anonymous() {
+                       // Disable this check enhancement in Go 1.12.1; some
+                       // false positives were spotted in the initial 1.12
+                       // release. See https://golang.org/issues/30465.
+                       return
+
                        typ, ok := field.Type().Underlying().(*types.Struct)
                        if !ok {
                                return
index 76dabc28b9043ba14d6c12538712ee286fdf85c4..ba2e66fed2f62118583635fd3f71826e6c180d4b 100644 (file)
@@ -329,6 +329,7 @@ func run(fset *token.FileSet, cfg *Config, analyzers []*analysis.Analyzer) ([]re
                                OtherFiles:        cfg.NonGoFiles,
                                Pkg:               pkg,
                                TypesInfo:         info,
+                               TypesSizes:        tc.Sizes,
                                ResultOf:          inputs,
                                Report:            func(d analysis.Diagnostic) { act.diagnostics = append(act.diagnostics, d) },
                                ImportObjectFact:  facts.ImportObjectFact,
index db88a951090a5a17a33dfea9c6f080c87165cdd1..ddbdd3f08fc2e5556865c9accf47713b5eee79e1 100644 (file)
@@ -14,7 +14,7 @@
 // Experiments suggest the inspector's traversals are about 2.5x faster
 // than ast.Inspect, but it may take around 5 traversals for this
 // benefit to amortize the inspector's construction cost.
-// If efficiency is the primary concern, do not use use Inspector for
+// If efficiency is the primary concern, do not use Inspector for
 // one-off traversals.
 package inspector