diff --git a/cmd/vet/copylock.go b/cmd/vet/copylock.go index e8a6820f..95cecc79 100644 --- a/cmd/vet/copylock.go +++ b/cmd/vet/copylock.go @@ -11,8 +11,7 @@ import ( "fmt" "go/ast" "go/token" - - "golang.org/x/tools/go/types" + "go/types" ) func init() { diff --git a/cmd/vet/main.go b/cmd/vet/main.go index 16b8842c..abc39fcf 100644 --- a/cmd/vet/main.go +++ b/cmd/vet/main.go @@ -15,14 +15,12 @@ import ( "go/parser" "go/printer" "go/token" + "go/types" "io/ioutil" "os" "path/filepath" "strconv" "strings" - - _ "golang.org/x/tools/go/gcimporter" - "golang.org/x/tools/go/types" ) // TODO: Need a flag to set build tags when parsing the package. diff --git a/cmd/vet/nilfunc.go b/cmd/vet/nilfunc.go index fa1bac7e..bfe05e33 100644 --- a/cmd/vet/nilfunc.go +++ b/cmd/vet/nilfunc.go @@ -12,8 +12,7 @@ package main import ( "go/ast" "go/token" - - "golang.org/x/tools/go/types" + "go/types" ) func init() { diff --git a/cmd/vet/print.go b/cmd/vet/print.go index b20d935e..58b4fae6 100644 --- a/cmd/vet/print.go +++ b/cmd/vet/print.go @@ -10,13 +10,12 @@ import ( "bytes" "flag" "go/ast" + "go/exact" "go/token" + "go/types" "strconv" "strings" "unicode/utf8" - - "golang.org/x/tools/go/exact" - "golang.org/x/tools/go/types" ) var printfuncs = flag.String("printfuncs", "", "comma-separated list of print function names to check") diff --git a/cmd/vet/shadow.go b/cmd/vet/shadow.go index 34e5db90..b3f362a0 100644 --- a/cmd/vet/shadow.go +++ b/cmd/vet/shadow.go @@ -34,8 +34,7 @@ import ( "flag" "go/ast" "go/token" - - "golang.org/x/tools/go/types" + "go/types" ) var strictShadowing = flag.Bool("shadowstrict", false, "whether to be strict about shadowing; can be noisy") diff --git a/cmd/vet/shift.go b/cmd/vet/shift.go index 2385c23f..7898d281 100644 --- a/cmd/vet/shift.go +++ b/cmd/vet/shift.go @@ -10,10 +10,9 @@ package main import ( "go/ast" + "go/exact" "go/token" - - "golang.org/x/tools/go/exact" - "golang.org/x/tools/go/types" + "go/types" ) func init() { diff --git a/cmd/vet/types.go b/cmd/vet/types.go index 89e9989d..57d1b5fd 100644 --- a/cmd/vet/types.go +++ b/cmd/vet/types.go @@ -8,14 +8,14 @@ package main import ( "go/ast" + "go/importer" "go/token" - - "golang.org/x/tools/go/types" + "go/types" ) -// imports is the canonical map of imported packages we need for typechecking. -// It is created during initialization. -var imports = make(map[string]*types.Package) +// The stdImporter implements importing from package files created by +// the compiler that built this binary. +var stdImporter = importer.Default() var ( stringerMethodType = types.New("func() string") @@ -35,7 +35,7 @@ func init() { // path.name, and adds the respective package to the imports map // as a side effect. func importType(path, name string) types.Type { - pkg, err := types.DefaultImport(imports, path) + pkg, err := stdImporter.Import(path) if err != nil { // This can happen if fmt hasn't been compiled yet. // Since nothing uses formatterType anyway, don't complain. @@ -56,12 +56,12 @@ func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) error { pkg.spans = make(map[types.Object]Span) pkg.types = make(map[ast.Expr]types.TypeAndValue) config := types.Config{ - // We provide the same packages map for all imports to ensure - // that everybody sees identical packages for the given paths. - Packages: imports, // By providing a Config with our own error function, it will continue // past the first error. There is no need for that function to do anything. Error: func(error) {}, + // We use the same importer for all imports to ensure + // that everybody sees identical packages for the given paths. + Importer: stdImporter, } info := &types.Info{ Selections: pkg.selectors, diff --git a/cmd/vet/unsafeptr.go b/cmd/vet/unsafeptr.go index ca15f725..9ca27dce 100644 --- a/cmd/vet/unsafeptr.go +++ b/cmd/vet/unsafeptr.go @@ -9,8 +9,7 @@ package main import ( "go/ast" "go/token" - - "golang.org/x/tools/go/types" + "go/types" ) func init() { diff --git a/cmd/vet/unused.go b/cmd/vet/unused.go index cbec9bb8..42876385 100644 --- a/cmd/vet/unused.go +++ b/cmd/vet/unused.go @@ -11,10 +11,8 @@ import ( "flag" "go/ast" "go/token" + "go/types" "strings" - - "golang.org/x/tools/go/ast/astutil" - "golang.org/x/tools/go/types" ) var unusedFuncsFlag = flag.String("unusedfuncs", @@ -56,11 +54,11 @@ func initUnusedFlags() { } func checkUnusedResult(f *File, n ast.Node) { - call, ok := astutil.Unparen(n.(*ast.ExprStmt).X).(*ast.CallExpr) + call, ok := unparen(n.(*ast.ExprStmt).X).(*ast.CallExpr) if !ok { return // not a call statement } - fun := astutil.Unparen(call.Fun) + fun := unparen(call.Fun) if f.pkg.types[fun].IsType() { return // a conversion, not a call