stdversion

Imports

Imports #

"go/ast"
"go/build"
"go/types"
"regexp"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/internal/typesinternal"
"golang.org/x/tools/internal/versions"

Constants & Variables

Analyzer var #

var Analyzer = *ast.UnaryExpr

Doc const #

const Doc = `report uses of too-new standard library symbols

The stdversion analyzer reports references to symbols in the standard
library that were introduced by a Go release higher than the one in
force in the referring file. (Recall that the file's Go version is
defined by the 'go' directive its module's go.mod file, or by a
"//go:build go1.X" build tag at the top of the file.)

The analyzer does not report a diagnostic for a reference to a "too
new" field or method of a type that is itself "too new", as this may
have false positives, for example if fields or methods are accessed
through a type alias that is guarded by a Go version constraint.
`

generatedRx var #

Matches cgo generated comment as well as the proposed standard: https://golang.org/s/generatedcode

var generatedRx = *ast.CallExpr

Functions

isGenerated function #

Reduced from x/tools/gopls/internal/golang/util.go. Good enough for now. TODO(adonovan): use ast.IsGenerated in go1.21.

func isGenerated(f *ast.File) bool

origin function #

origin returns the original uninstantiated symbol for obj.

func origin(obj types.Object) types.Object

run function #

func run(pass *analysis.Pass) (any, error)

slicesContains function #

TODO(adonovan): use go1.21 slices.Contains.

func slicesContains(slice S, x E) bool

Generated with Arrow