Skip to content

Commit

Permalink
internal/versions: remove constraint.GoVersion wrapper
Browse files Browse the repository at this point in the history
Remove the constraint.GoVersion wrapper as x/tools can now assume >=go1.21.

Change-Id: I3bd0669d28cabc26cf63c299b3eb51c6a6adc0d0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/632356
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Commit-Queue: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
timothy-king authored and Go LUCI committed Nov 28, 2024
1 parent c99edec commit e71702b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 46 deletions.
25 changes: 6 additions & 19 deletions go/analysis/passes/buildtag/buildtag.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/internal/versions"
)

const Doc = "check //go:build and // +build directives"
Expand Down Expand Up @@ -371,11 +370,6 @@ func (check *checker) finish() {

// tags reports issues in go versions in tags within the expression e.
func (check *checker) tags(pos token.Pos, e constraint.Expr) {
// Check that constraint.GoVersion is meaningful (>= go1.21).
if versions.ConstraintGoVersion == nil {
return
}

// Use Eval to visit each tag.
_ = e.Eval(func(tag string) bool {
if malformedGoTag(tag) {
Expand All @@ -393,26 +387,19 @@ func malformedGoTag(tag string) bool {
// Check for close misspellings of the "go1." prefix.
for _, pre := range []string{"go.", "g1.", "go"} {
suffix := strings.TrimPrefix(tag, pre)
if suffix != tag {
if valid, ok := validTag("go1." + suffix); ok && valid {
return true
}
if suffix != tag && validGoVersion("go1."+suffix) {
return true
}
}
return false
}

// The tag starts with "go1" so it is almost certainly a GoVersion.
// Report it if it is not a valid build constraint.
valid, ok := validTag(tag)
return ok && !valid
return !validGoVersion(tag)
}

// validTag returns (valid, ok) where valid reports when a tag is valid,
// and ok reports determining if the tag is valid succeeded.
func validTag(tag string) (valid bool, ok bool) {
if versions.ConstraintGoVersion != nil {
return versions.ConstraintGoVersion(&constraint.TagExpr{Tag: tag}) != "", true
}
return false, false
// validGoVersion reports when a tag is a valid go version.
func validGoVersion(tag string) bool {
return constraint.GoVersion(&constraint.TagExpr{Tag: tag}) != ""
}
13 changes: 0 additions & 13 deletions internal/versions/constraint.go

This file was deleted.

14 changes: 0 additions & 14 deletions internal/versions/constraint_go121.go

This file was deleted.

0 comments on commit e71702b

Please sign in to comment.