...

Source file src/cmd/vendor/golang.org/x/tools/internal/versions/features.go

Documentation: cmd/vendor/golang.org/x/tools/internal/versions

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package versions
     6  
     7  // This file contains predicates for working with file versions to
     8  // decide when a tool should consider a language feature enabled.
     9  
    10  // GoVersions that features in x/tools can be gated to.
    11  const (
    12  	Go1_18 = "go1.18"
    13  	Go1_19 = "go1.19"
    14  	Go1_20 = "go1.20"
    15  	Go1_21 = "go1.21"
    16  	Go1_22 = "go1.22"
    17  )
    18  
    19  // Future is an invalid unknown Go version sometime in the future.
    20  // Do not use directly with Compare.
    21  const Future = ""
    22  
    23  // AtLeast reports whether the file version v comes after a Go release.
    24  //
    25  // Use this predicate to enable a behavior once a certain Go release
    26  // has happened (and stays enabled in the future).
    27  func AtLeast(v, release string) bool {
    28  	if v == Future {
    29  		return true // an unknown future version is always after y.
    30  	}
    31  	return Compare(Lang(v), Lang(release)) >= 0
    32  }
    33  
    34  // Before reports whether the file version v is strictly before a Go release.
    35  //
    36  // Use this predicate to disable a behavior once a certain Go release
    37  // has happened (and stays enabled in the future).
    38  func Before(v, release string) bool {
    39  	if v == Future {
    40  		return false // an unknown future version happens after y.
    41  	}
    42  	return Compare(Lang(v), Lang(release)) < 0
    43  }
    44  

View as plain text