@@ -15,7 +15,6 @@ import (
15
15
16
16
"golang.org/x/tools/go/analysis"
17
17
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
18
- "golang.org/x/tools/internal/versions"
19
18
)
20
19
21
20
const Doc = "check //go:build and // +build directives"
@@ -371,11 +370,6 @@ func (check *checker) finish() {
371
370
372
371
// tags reports issues in go versions in tags within the expression e.
373
372
func (check * checker ) tags (pos token.Pos , e constraint.Expr ) {
374
- // Check that constraint.GoVersion is meaningful (>= go1.21).
375
- if versions .ConstraintGoVersion == nil {
376
- return
377
- }
378
-
379
373
// Use Eval to visit each tag.
380
374
_ = e .Eval (func (tag string ) bool {
381
375
if malformedGoTag (tag ) {
@@ -393,26 +387,19 @@ func malformedGoTag(tag string) bool {
393
387
// Check for close misspellings of the "go1." prefix.
394
388
for _ , pre := range []string {"go." , "g1." , "go" } {
395
389
suffix := strings .TrimPrefix (tag , pre )
396
- if suffix != tag {
397
- if valid , ok := validTag ("go1." + suffix ); ok && valid {
398
- return true
399
- }
390
+ if suffix != tag && validGoVersion ("go1." + suffix ) {
391
+ return true
400
392
}
401
393
}
402
394
return false
403
395
}
404
396
405
397
// The tag starts with "go1" so it is almost certainly a GoVersion.
406
398
// Report it if it is not a valid build constraint.
407
- valid , ok := validTag (tag )
408
- return ok && ! valid
399
+ return ! validGoVersion (tag )
409
400
}
410
401
411
- // validTag returns (valid, ok) where valid reports when a tag is valid,
412
- // and ok reports determining if the tag is valid succeeded.
413
- func validTag (tag string ) (valid bool , ok bool ) {
414
- if versions .ConstraintGoVersion != nil {
415
- return versions .ConstraintGoVersion (& constraint.TagExpr {Tag : tag }) != "" , true
416
- }
417
- return false , false
402
+ // validGoVersion reports when a tag is a valid go version.
403
+ func validGoVersion (tag string ) bool {
404
+ return constraint .GoVersion (& constraint.TagExpr {Tag : tag }) != ""
418
405
}
0 commit comments