diff --git a/cmd/vet/copylock.go b/cmd/vet/copylock.go index 95cecc79..e8a6820f 100644 --- a/cmd/vet/copylock.go +++ b/cmd/vet/copylock.go @@ -11,7 +11,8 @@ import ( "fmt" "go/ast" "go/token" - "go/types" + + "golang.org/x/tools/go/types" ) func init() { diff --git a/cmd/vet/example.go b/cmd/vet/example.go index 797c3cee..585d3884 100644 --- a/cmd/vet/example.go +++ b/cmd/vet/example.go @@ -6,10 +6,11 @@ package main import ( "go/ast" - "go/types" "strings" "unicode" "unicode/utf8" + + "golang.org/x/tools/go/types" ) func init() { diff --git a/cmd/vet/main.go b/cmd/vet/main.go index 8bef050d..c86e13c4 100644 --- a/cmd/vet/main.go +++ b/cmd/vet/main.go @@ -18,12 +18,14 @@ 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" ) var ( diff --git a/cmd/vet/nilfunc.go b/cmd/vet/nilfunc.go index bfe05e33..fa1bac7e 100644 --- a/cmd/vet/nilfunc.go +++ b/cmd/vet/nilfunc.go @@ -12,7 +12,8 @@ package main import ( "go/ast" "go/token" - "go/types" + + "golang.org/x/tools/go/types" ) func init() { diff --git a/cmd/vet/print.go b/cmd/vet/print.go index 42c86a51..b20d935e 100644 --- a/cmd/vet/print.go +++ b/cmd/vet/print.go @@ -10,12 +10,13 @@ import ( "bytes" "flag" "go/ast" - exact "go/constant" "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 2149e70c..fa680a03 100644 --- a/cmd/vet/shadow.go +++ b/cmd/vet/shadow.go @@ -34,7 +34,8 @@ import ( "flag" "go/ast" "go/token" - "go/types" + + "golang.org/x/tools/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 e70bfcfb..2385c23f 100644 --- a/cmd/vet/shift.go +++ b/cmd/vet/shift.go @@ -10,9 +10,10 @@ package main import ( "go/ast" - exact "go/constant" "go/token" - "go/types" + + "golang.org/x/tools/go/exact" + "golang.org/x/tools/go/types" ) func init() { diff --git a/cmd/vet/types.go b/cmd/vet/types.go index 46478237..084be85d 100644 --- a/cmd/vet/types.go +++ b/cmd/vet/types.go @@ -8,9 +8,9 @@ package main import ( "go/ast" - "go/importer" "go/token" - "go/types" + + "golang.org/x/tools/go/types" ) // imports is the canonical map of imported packages we need for typechecking. @@ -18,8 +18,6 @@ import ( var imports = make(map[string]*types.Package) var ( - defaultImporter = importer.Default() - errorType *types.Interface stringerType *types.Interface // possibly nil formatterType *types.Interface // possibly nil @@ -41,7 +39,7 @@ func init() { // path.name, and adds the respective package to the imports map // as a side effect. In case of an error, importType returns nil. func importType(path, name string) types.Type { - pkg, err := defaultImporter.Import(path) + pkg, err := types.DefaultImport(imports, path) if err != nil { // This can happen if the package at path hasn't been compiled yet. warnf("import failed: %v", err) @@ -61,7 +59,9 @@ 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{ - Importer: defaultImporter, + // 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) {}, diff --git a/cmd/vet/unsafeptr.go b/cmd/vet/unsafeptr.go index 9ca27dce..ca15f725 100644 --- a/cmd/vet/unsafeptr.go +++ b/cmd/vet/unsafeptr.go @@ -9,7 +9,8 @@ package main import ( "go/ast" "go/token" - "go/types" + + "golang.org/x/tools/go/types" ) func init() { diff --git a/cmd/vet/unused.go b/cmd/vet/unused.go index df2317a4..b9d7b65f 100644 --- a/cmd/vet/unused.go +++ b/cmd/vet/unused.go @@ -11,8 +11,9 @@ import ( "flag" "go/ast" "go/token" - "go/types" "strings" + + "golang.org/x/tools/go/types" ) var unusedFuncsFlag = flag.String("unusedfuncs",