summaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/tools/internal/aliases
diff options
context:
space:
mode:
authorLibravatar Terin Stock <terinjokes@gmail.com>2025-03-09 17:47:56 +0100
committerLibravatar Terin Stock <terinjokes@gmail.com>2025-03-10 01:59:49 +0100
commit3ac1ee16f377d31a0fb80c8dae28b6239ac4229e (patch)
treef61faa581feaaeaba2542b9f2b8234a590684413 /vendor/golang.org/x/tools/internal/aliases
parent[chore] update URLs to forked source (diff)
downloadgotosocial-3ac1ee16f377d31a0fb80c8dae28b6239ac4229e.tar.xz
[chore] remove vendor
Diffstat (limited to 'vendor/golang.org/x/tools/internal/aliases')
-rw-r--r--vendor/golang.org/x/tools/internal/aliases/aliases.go38
-rw-r--r--vendor/golang.org/x/tools/internal/aliases/aliases_go122.go80
2 files changed, 0 insertions, 118 deletions
diff --git a/vendor/golang.org/x/tools/internal/aliases/aliases.go b/vendor/golang.org/x/tools/internal/aliases/aliases.go
deleted file mode 100644
index b9425f5a2..000000000
--- a/vendor/golang.org/x/tools/internal/aliases/aliases.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2024 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package aliases
-
-import (
- "go/token"
- "go/types"
-)
-
-// Package aliases defines backward compatible shims
-// for the types.Alias type representation added in 1.22.
-// This defines placeholders for x/tools until 1.26.
-
-// NewAlias creates a new TypeName in Package pkg that
-// is an alias for the type rhs.
-//
-// The enabled parameter determines whether the resulting [TypeName]'s
-// type is an [types.Alias]. Its value must be the result of a call to
-// [Enabled], which computes the effective value of
-// GODEBUG=gotypesalias=... by invoking the type checker. The Enabled
-// function is expensive and should be called once per task (e.g.
-// package import), not once per call to NewAlias.
-//
-// Precondition: enabled || len(tparams)==0.
-// If materialized aliases are disabled, there must not be any type parameters.
-func NewAlias(enabled bool, pos token.Pos, pkg *types.Package, name string, rhs types.Type, tparams []*types.TypeParam) *types.TypeName {
- if enabled {
- tname := types.NewTypeName(pos, pkg, name, nil)
- SetTypeParams(types.NewAlias(tname, rhs), tparams)
- return tname
- }
- if len(tparams) > 0 {
- panic("cannot create an alias with type parameters when gotypesalias is not enabled")
- }
- return types.NewTypeName(pos, pkg, name, rhs)
-}
diff --git a/vendor/golang.org/x/tools/internal/aliases/aliases_go122.go b/vendor/golang.org/x/tools/internal/aliases/aliases_go122.go
deleted file mode 100644
index 7716a3331..000000000
--- a/vendor/golang.org/x/tools/internal/aliases/aliases_go122.go
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright 2024 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package aliases
-
-import (
- "go/ast"
- "go/parser"
- "go/token"
- "go/types"
-)
-
-// Rhs returns the type on the right-hand side of the alias declaration.
-func Rhs(alias *types.Alias) types.Type {
- if alias, ok := any(alias).(interface{ Rhs() types.Type }); ok {
- return alias.Rhs() // go1.23+
- }
-
- // go1.22's Alias didn't have the Rhs method,
- // so Unalias is the best we can do.
- return types.Unalias(alias)
-}
-
-// TypeParams returns the type parameter list of the alias.
-func TypeParams(alias *types.Alias) *types.TypeParamList {
- if alias, ok := any(alias).(interface{ TypeParams() *types.TypeParamList }); ok {
- return alias.TypeParams() // go1.23+
- }
- return nil
-}
-
-// SetTypeParams sets the type parameters of the alias type.
-func SetTypeParams(alias *types.Alias, tparams []*types.TypeParam) {
- if alias, ok := any(alias).(interface {
- SetTypeParams(tparams []*types.TypeParam)
- }); ok {
- alias.SetTypeParams(tparams) // go1.23+
- } else if len(tparams) > 0 {
- panic("cannot set type parameters of an Alias type in go1.22")
- }
-}
-
-// TypeArgs returns the type arguments used to instantiate the Alias type.
-func TypeArgs(alias *types.Alias) *types.TypeList {
- if alias, ok := any(alias).(interface{ TypeArgs() *types.TypeList }); ok {
- return alias.TypeArgs() // go1.23+
- }
- return nil // empty (go1.22)
-}
-
-// Origin returns the generic Alias type of which alias is an instance.
-// If alias is not an instance of a generic alias, Origin returns alias.
-func Origin(alias *types.Alias) *types.Alias {
- if alias, ok := any(alias).(interface{ Origin() *types.Alias }); ok {
- return alias.Origin() // go1.23+
- }
- return alias // not an instance of a generic alias (go1.22)
-}
-
-// Enabled reports whether [NewAlias] should create [types.Alias] types.
-//
-// This function is expensive! Call it sparingly.
-func Enabled() bool {
- // The only reliable way to compute the answer is to invoke go/types.
- // We don't parse the GODEBUG environment variable, because
- // (a) it's tricky to do so in a manner that is consistent
- // with the godebug package; in particular, a simple
- // substring check is not good enough. The value is a
- // rightmost-wins list of options. But more importantly:
- // (b) it is impossible to detect changes to the effective
- // setting caused by os.Setenv("GODEBUG"), as happens in
- // many tests. Therefore any attempt to cache the result
- // is just incorrect.
- fset := token.NewFileSet()
- f, _ := parser.ParseFile(fset, "a.go", "package p; type A = int", parser.SkipObjectResolution)
- pkg, _ := new(types.Config).Check("p", fset, []*ast.File{f}, nil)
- _, enabled := pkg.Scope().Lookup("A").Type().(*types.Alias)
- return enabled
-}