1
0
mirror of https://github.com/golang/go synced 2024-11-26 01:17:57 -07:00

all: gofmt -w -r 'interface{} -> any' src

And then revert the bootstrap cmd directories and certain testdata.
And adjust tests as needed.

Not reverting the changes in std that are bootstrapped,
because some of those changes would appear in API docs,
and we want to use any consistently.
Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories
when preparing the bootstrap copy.

A few files changed as a result of running gofmt -w
not because of interface{} -> any but because they
hadn't been updated for the new //go:build lines.

Fixes #49884.

Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09
Reviewed-on: https://go-review.googlesource.com/c/go/+/368254
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Russ Cox 2021-12-01 12:15:45 -05:00
parent 083ef54624
commit 2580d0e08d
445 changed files with 1906 additions and 1875 deletions

View File

@ -538,7 +538,7 @@ type headerFileInfo struct {
func (fi headerFileInfo) Size() int64 { return fi.h.Size }
func (fi headerFileInfo) IsDir() bool { return fi.Mode().IsDir() }
func (fi headerFileInfo) ModTime() time.Time { return fi.h.ModTime }
func (fi headerFileInfo) Sys() interface{} { return fi.h }
func (fi headerFileInfo) Sys() any { return fi.h }
// Name returns the base name of the file.
func (fi headerFileInfo) Name() string {

View File

@ -1363,7 +1363,7 @@ func TestFileReader(t *testing.T) {
wantLCnt int64
wantPCnt int64
}
testFnc interface{} // testRead | testWriteTo | testRemaining
testFnc any // testRead | testWriteTo | testRemaining
)
type (
@ -1376,7 +1376,7 @@ func TestFileReader(t *testing.T) {
spd sparseDatas
size int64
}
fileMaker interface{} // makeReg | makeSparse
fileMaker any // makeReg | makeSparse
)
vectors := []struct {

View File

@ -23,7 +23,7 @@ import (
type testError struct{ error }
type fileOps []interface{} // []T where T is (string | int64)
type fileOps []any // []T where T is (string | int64)
// testFile is an io.ReadWriteSeeker where the IO operations performed
// on it must match the list of operations in ops.

View File

@ -67,7 +67,7 @@ func TestWriter(t *testing.T) {
testClose struct { // Close() == wantErr
wantErr error
}
testFnc interface{} // testHeader | testWrite | testReadFrom | testClose
testFnc any // testHeader | testWrite | testReadFrom | testClose
)
vectors := []struct {
@ -1031,7 +1031,7 @@ func TestFileWriter(t *testing.T) {
wantLCnt int64
wantPCnt int64
}
testFnc interface{} // testWrite | testReadFrom | testRemaining
testFnc any // testWrite | testReadFrom | testRemaining
)
type (
@ -1044,7 +1044,7 @@ func TestFileWriter(t *testing.T) {
sph sparseHoles
size int64
}
fileMaker interface{} // makeReg | makeSparse
fileMaker any // makeReg | makeSparse
)
vectors := []struct {

View File

@ -670,7 +670,7 @@ func (f *fileListEntry) Size() int64 { return 0 }
func (f *fileListEntry) Mode() fs.FileMode { return fs.ModeDir | 0555 }
func (f *fileListEntry) Type() fs.FileMode { return fs.ModeDir }
func (f *fileListEntry) IsDir() bool { return true }
func (f *fileListEntry) Sys() interface{} { return nil }
func (f *fileListEntry) Sys() any { return nil }
func (f *fileListEntry) ModTime() time.Time {
if f.file == nil {

View File

@ -163,7 +163,7 @@ func (fi headerFileInfo) ModTime() time.Time {
}
func (fi headerFileInfo) Mode() fs.FileMode { return fi.fh.Mode() }
func (fi headerFileInfo) Type() fs.FileMode { return fi.fh.Mode().Type() }
func (fi headerFileInfo) Sys() interface{} { return fi.fh }
func (fi headerFileInfo) Sys() any { return fi.fh }
func (fi headerFileInfo) Info() (fs.FileInfo, error) { return fi, nil }

View File

@ -239,7 +239,7 @@ func close(c chan<- Type)
// that point, the program is terminated with a non-zero exit code. This
// termination sequence is called panicking and can be controlled by the
// built-in function recover.
func panic(v interface{})
func panic(v any)
// The recover built-in function allows a program to manage behavior of a
// panicking goroutine. Executing a call to recover inside a deferred
@ -250,7 +250,7 @@ func panic(v interface{})
// panicking, or if the argument supplied to panic was nil, recover returns
// nil. Thus the return value from recover reports whether the goroutine is
// panicking.
func recover() interface{}
func recover() any
// The print built-in function formats its arguments in an
// implementation-specific way and writes the result to standard error.

View File

@ -76,7 +76,7 @@ func TestReaderAt(t *testing.T) {
off int64
n int
want string
wanterr interface{}
wanterr any
}{
{0, 10, "0123456789", nil},
{1, 10, "123456789", io.EOF},

View File

@ -1071,7 +1071,7 @@ func (w *Walker) emitMethod(m *types.Selection) {
w.emitf("method (%s%s) %s%s", w.typeString(recv), tps, m.Obj().Name(), w.signatureString(sig))
}
func (w *Walker) emitf(format string, args ...interface{}) {
func (w *Walker) emitf(format string, args ...any) {
f := strings.Join(w.scope, ", ") + ", " + fmt.Sprintf(format, args...)
if strings.Contains(f, "\n") {
panic("feature contains newlines: " + f)

View File

@ -1,3 +1,4 @@
//go:build !amd64
// +build !amd64
package p

View File

@ -197,7 +197,7 @@ var m map[string]int
var chanVar chan int
var ifaceVar interface{} = 5
var ifaceVar any = 5
var assertVar = ifaceVar.(int)

View File

@ -4,12 +4,12 @@
package p4
type Pair[T1 interface { M() }, T2 ~int] struct {
type Pair[T1 interface{ M() }, T2 ~int] struct {
f1 T1
f2 T2
}
func NewPair[T1 interface { M() }, T2 ~int](v1 T1, v2 T2) Pair[T1, T2] {
func NewPair[T1 interface{ M() }, T2 ~int](v1 T1, v2 T2) Pair[T1, T2] {
return Pair[T1, T2]{f1: v1, f2: v2}
}

View File

@ -258,7 +258,7 @@ var importedObjectTests = []struct {
{"go/internal/gcimporter.FindPkg", "func FindPkg(path string, srcDir string) (filename string, id string)"},
// interfaces
{"context.Context", "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key interface{}) interface{}}"},
{"context.Context", "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key any) any}"},
{"crypto.Decrypter", "type Decrypter interface{Decrypt(rand io.Reader, msg []byte, opts DecrypterOpts) (plaintext []byte, err error); Public() PublicKey}"},
{"encoding.BinaryMarshaler", "type BinaryMarshaler interface{MarshalBinary() (data []byte, err error)}"},
{"io.Reader", "type Reader interface{Read(p []byte) (n int, err error)}"},

View File

@ -151,7 +151,7 @@ func testSwitch() {
}
func testTypeSwitch() {
var x = []interface{}{1, 2.0, "hi"}
var x = []any{1, 2.0, "hi"}
for _, v := range x {
switch func() { check(LINE, 3) }(); v.(type) {
case int:
@ -215,7 +215,7 @@ func testEmptySwitches() {
switch 3 {
}
check(LINE, 1)
switch i := (interface{})(3).(int); i {
switch i := (any)(3).(int); i {
}
check(LINE, 1)
c := make(chan int)

View File

@ -15,6 +15,7 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
)
@ -288,7 +289,11 @@ func rewriteBlock%s(b *Block) bool { panic("unused during bootstrap") }
}
func bootstrapFixImports(srcFile string) string {
lines := strings.SplitAfter(readfile(srcFile), "\n")
text := readfile(srcFile)
if !strings.Contains(srcFile, "/cmd/") && !strings.Contains(srcFile, `\cmd\`) {
text = regexp.MustCompile(`\bany\b`).ReplaceAllString(text, "interface{}")
}
lines := strings.SplitAfter(text, "\n")
inBlock := false
for i, line := range lines {
if strings.HasPrefix(line, "import (") {

View File

@ -122,7 +122,7 @@ func trim(path, prefix string) (string, bool) {
// main do function, so it doesn't cause an exit. Allows testing to work
// without running a subprocess. The log prefix will be added when
// logged in main; it is not added here.
func (pkg *Package) Fatalf(format string, args ...interface{}) {
func (pkg *Package) Fatalf(format string, args ...any) {
panic(PackageError(fmt.Sprintf(format, args...)))
}
@ -209,7 +209,7 @@ func parsePackage(writer io.Writer, pkg *build.Package, userPath string) *Packag
return p
}
func (pkg *Package) Printf(format string, args ...interface{}) {
func (pkg *Package) Printf(format string, args ...any) {
fmt.Fprintf(&pkg.buf, format, args...)
}
@ -235,7 +235,7 @@ func (pkg *Package) newlines(n int) {
// clears the stuff we don't want to print anyway. It's a bit of a magic trick.
func (pkg *Package) emit(comment string, node ast.Node) {
if node != nil {
var arg interface{} = node
var arg any = node
if showSrc {
// Need an extra little dance to get internal comments to appear.
arg = &printer.CommentedNode{

View File

@ -1,3 +1,4 @@
//go:build ignore
// +build ignore
// Ignored package

View File

@ -45,8 +45,8 @@ func typefix(f *ast.File, badType func(string) bool) bool {
// step 1: Find all the nils with the offending types.
// Compute their replacement.
badNils := map[interface{}]ast.Expr{}
walk(f, func(n interface{}) {
badNils := map[any]ast.Expr{}
walk(f, func(n any) {
if i, ok := n.(*ast.Ident); ok && i.Name == "nil" && badType(typeof[n]) {
badNils[n] = &ast.BasicLit{ValuePos: i.NamePos, Kind: token.INT, Value: "0"}
}
@ -58,7 +58,7 @@ func typefix(f *ast.File, badType func(string) bool) bool {
if len(badNils) > 0 {
exprType := reflect.TypeOf((*ast.Expr)(nil)).Elem()
exprSliceType := reflect.TypeOf(([]ast.Expr)(nil))
walk(f, func(n interface{}) {
walk(f, func(n any) {
if n == nil {
return
}
@ -99,7 +99,7 @@ func typefix(f *ast.File, badType func(string) bool) bool {
// Now we need unsafe.Pointer as an intermediate cast.
// (*unsafe.Pointer)(x) where x is type *bad -> (*unsafe.Pointer)(unsafe.Pointer(x))
// (*bad.type)(x) where x is type *unsafe.Pointer -> (*bad.type)(unsafe.Pointer(x))
walk(f, func(n interface{}) {
walk(f, func(n any) {
if n == nil {
return
}

View File

@ -43,15 +43,15 @@ func register(f fix) {
// walk traverses the AST x, calling visit(y) for each node y in the tree but
// also with a pointer to each ast.Expr, ast.Stmt, and *ast.BlockStmt,
// in a bottom-up traversal.
func walk(x interface{}, visit func(interface{})) {
func walk(x any, visit func(any)) {
walkBeforeAfter(x, nop, visit)
}
func nop(interface{}) {}
func nop(any) {}
// walkBeforeAfter is like walk but calls before(x) before traversing
// x's children and after(x) afterward.
func walkBeforeAfter(x interface{}, before, after func(interface{})) {
func walkBeforeAfter(x any, before, after func(any)) {
before(x)
switch n := x.(type) {
@ -390,7 +390,7 @@ func renameTop(f *ast.File, old, new string) bool {
// Rename top-level old to new, both unresolved names
// (probably defined in another file) and names that resolve
// to a declaration we renamed.
walk(f, func(n interface{}) {
walk(f, func(n any) {
id, ok := n.(*ast.Ident)
if ok && isTopName(id, old) {
id.Name = new

View File

@ -36,7 +36,7 @@ func fixGoExact(f *ast.File) bool {
// This one is harder because the import name changes.
// First find the import spec.
var importSpec *ast.ImportSpec
walk(f, func(n interface{}) {
walk(f, func(n any) {
if importSpec != nil {
return
}

View File

@ -245,7 +245,7 @@ func processFile(filename string, useStdin bool) error {
return os.WriteFile(f.Name(), newSrc, 0)
}
func gofmt(n interface{}) string {
func gofmt(n any) string {
var gofmtBuf bytes.Buffer
if err := format.Node(&gofmtBuf, fset, n); err != nil {
return "<" + err.Error() + ">"

View File

@ -26,7 +26,7 @@ func netipv6zone(f *ast.File) bool {
}
fixed := false
walk(f, func(n interface{}) {
walk(f, func(n any) {
cl, ok := n.(*ast.CompositeLit)
if !ok {
return

View File

@ -23,7 +23,7 @@ func printerconfig(f *ast.File) bool {
}
fixed := false
walk(f, func(n interface{}) {
walk(f, func(n any) {
cl, ok := n.(*ast.CompositeLit)
if !ok {
return

View File

@ -142,9 +142,9 @@ func (typ *Type) dot(cfg *TypeConfig, name string) string {
// typeof maps AST nodes to type information in gofmt string form.
// assign maps type strings to lists of expressions that were assigned
// to values of another type that were assigned to that type.
func typecheck(cfg *TypeConfig, f *ast.File) (typeof map[interface{}]string, assign map[string][]interface{}) {
typeof = make(map[interface{}]string)
assign = make(map[string][]interface{})
func typecheck(cfg *TypeConfig, f *ast.File) (typeof map[any]string, assign map[string][]any) {
typeof = make(map[any]string)
assign = make(map[string][]any)
cfg1 := &TypeConfig{}
*cfg1 = *cfg // make copy so we can add locally
copied := false
@ -296,7 +296,7 @@ func makeExprList(a []*ast.Ident) []ast.Expr {
// Typecheck1 is the recursive form of typecheck.
// It is like typecheck but adds to the information in typeof
// instead of allocating a new map.
func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, assign map[string][]interface{}) {
func typecheck1(cfg *TypeConfig, f any, typeof map[any]string, assign map[string][]any) {
// set sets the type of n to typ.
// If isDecl is true, n is being declared.
set := func(n ast.Expr, typ string, isDecl bool) {
@ -368,7 +368,7 @@ func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, a
// the curfn stack.
var curfn []*ast.FuncType
before := func(n interface{}) {
before := func(n any) {
// push function type on stack
switch n := n.(type) {
case *ast.FuncDecl:
@ -379,7 +379,7 @@ func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, a
}
// After is the real type checker.
after := func(n interface{}) {
after := func(n any) {
if n == nil {
return
}

View File

@ -117,12 +117,12 @@ func Exit() {
os.Exit(exitStatus)
}
func Fatalf(format string, args ...interface{}) {
func Fatalf(format string, args ...any) {
Errorf(format, args...)
Exit()
}
func Errorf(format string, args ...interface{}) {
func Errorf(format string, args ...any) {
log.Printf(format, args...)
SetExitStatus(1)
}
@ -151,7 +151,7 @@ func GetExitStatus() int {
// Run runs the command, with stdout and stderr
// connected to the go command's own stdout and stderr.
// If the command fails, Run reports the error using Errorf.
func Run(cmdargs ...interface{}) {
func Run(cmdargs ...any) {
cmdline := str.StringList(cmdargs...)
if cfg.BuildN || cfg.BuildX {
fmt.Printf("%s\n", strings.Join(cmdline, " "))

View File

@ -92,7 +92,7 @@ func ParseOne(fs *flag.FlagSet, args []string) (f *flag.Flag, remainingArgs []st
// Use fs.Set instead of f.Value.Set below so that any subsequent call to
// fs.Visit will correctly visit the flags that have been set.
failf := func(format string, a ...interface{}) (*flag.Flag, []string, error) {
failf := func(format string, a ...any) (*flag.Flag, []string, error) {
return f, args, fmt.Errorf(format, a...)
}

View File

@ -499,7 +499,7 @@ func (f fakeFile) Size() int64 { return f.real.Size() }
func (f fakeFile) Mode() fs.FileMode { return f.real.Mode() }
func (f fakeFile) ModTime() time.Time { return f.real.ModTime() }
func (f fakeFile) IsDir() bool { return f.real.IsDir() }
func (f fakeFile) Sys() interface{} { return f.real.Sys() }
func (f fakeFile) Sys() any { return f.real.Sys() }
// missingFile provides an fs.FileInfo for an overlaid file where the
// destination file in the overlay doesn't exist. It returns zero values
@ -512,7 +512,7 @@ func (f missingFile) Size() int64 { return 0 }
func (f missingFile) Mode() fs.FileMode { return fs.ModeIrregular }
func (f missingFile) ModTime() time.Time { return time.Unix(0, 0) }
func (f missingFile) IsDir() bool { return false }
func (f missingFile) Sys() interface{} { return nil }
func (f missingFile) Sys() any { return nil }
// fakeDir provides an fs.FileInfo implementation for directories that are
// implicitly created by overlaid files. Each directory in the
@ -524,7 +524,7 @@ func (f fakeDir) Size() int64 { return 0 }
func (f fakeDir) Mode() fs.FileMode { return fs.ModeDir | 0500 }
func (f fakeDir) ModTime() time.Time { return time.Unix(0, 0) }
func (f fakeDir) IsDir() bool { return true }
func (f fakeDir) Sys() interface{} { return nil }
func (f fakeDir) Sys() any { return nil }
// Glob is like filepath.Glob but uses the overlay file system.
func Glob(pattern string) (matches []string, err error) {

View File

@ -408,7 +408,7 @@ var stop = fmt.Errorf("error in generation")
// errorf logs an error message prefixed with the file and line number.
// It then exits the program (with exit status 1) because generation stops
// at the first error.
func (g *Generator) errorf(format string, args ...interface{}) {
func (g *Generator) errorf(format string, args ...any) {
fmt.Fprintf(os.Stderr, "%s:%d: %s\n", base.ShortPath(g.path), g.lineNum,
fmt.Sprintf(format, args...))
panic(stop)

View File

@ -162,7 +162,7 @@ func (w *errWriter) Write(b []byte) (int, error) {
}
// tmpl executes the given template text on data, writing the result to w.
func tmpl(w io.Writer, text string, data interface{}) {
func tmpl(w io.Writer, text string, data any) {
t := template.New("top")
t.Funcs(template.FuncMap{"trim": strings.TrimSpace, "capitalize": capitalize})
template.Must(t.Parse(text))

View File

@ -1,3 +1,4 @@
//go:build android
// +build android
package android

View File

@ -1,3 +1,4 @@
//go:build linux
// +build linux
package android

View File

@ -1,3 +1,4 @@
//go:build !android
// +build !android
package android

View File

@ -1,3 +1,4 @@
//go:build illumos
// +build illumos
package illumos

View File

@ -1,3 +1,4 @@
//go:build solaris
// +build solaris
package illumos

View File

@ -1,3 +1,4 @@
//go:build !illumos
// +build !illumos
package illumos

View File

@ -1,8 +1,5 @@
// +build blahblh
// +build linux
// +build !linux
// +build windows
// +build darwin
//go:build blahblh && linux && !linux && windows && darwin
// +build blahblh,linux,!linux,windows,darwin
package x

View File

@ -358,9 +358,9 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
}
}
var do func(interface{})
var do func(any)
if *listJson {
do = func(x interface{}) {
do = func(x any) {
b, err := json.MarshalIndent(x, "", "\t")
if err != nil {
out.Flush()
@ -386,7 +386,7 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
if err != nil {
base.Fatalf("%s", err)
}
do = func(x interface{}) {
do = func(x any) {
if err := tmpl.Execute(out, x); err != nil {
out.Flush()
base.Fatalf("%s", err)

View File

@ -498,7 +498,7 @@ type importError struct {
err error // created with fmt.Errorf
}
func ImportErrorf(path, format string, args ...interface{}) ImportPathError {
func ImportErrorf(path, format string, args ...any) ImportPathError {
err := &importError{importPath: path, err: fmt.Errorf(format, args...)}
if errStr := err.Error(); !strings.Contains(errStr, path) {
panic(fmt.Sprintf("path %q not in error %q", path, errStr))
@ -589,10 +589,10 @@ func ClearPackageCachePartial(args []string) {
delete(packageCache, arg)
}
}
resolvedImportCache.DeleteIf(func(key interface{}) bool {
resolvedImportCache.DeleteIf(func(key any) bool {
return shouldDelete[key.(importSpec).path]
})
packageDataCache.DeleteIf(func(key interface{}) bool {
packageDataCache.DeleteIf(func(key any) bool {
return shouldDelete[key.(string)]
})
}
@ -605,7 +605,7 @@ func ReloadPackageNoFlags(arg string, stk *ImportStack) *Package {
p := packageCache[arg]
if p != nil {
delete(packageCache, arg)
resolvedImportCache.DeleteIf(func(key interface{}) bool {
resolvedImportCache.DeleteIf(func(key any) bool {
return key.(importSpec).path == p.ImportPath
})
packageDataCache.Delete(p.ImportPath)
@ -817,7 +817,7 @@ func loadPackageData(ctx context.Context, path, parentPath, parentDir, parentRoo
parentIsStd: parentIsStd,
mode: mode,
}
r := resolvedImportCache.Do(importKey, func() interface{} {
r := resolvedImportCache.Do(importKey, func() any {
var r resolvedImport
if build.IsLocalImport(path) {
r.dir = filepath.Join(parentDir, path)
@ -844,7 +844,7 @@ func loadPackageData(ctx context.Context, path, parentPath, parentDir, parentRoo
// Load the package from its directory. If we already found the package's
// directory when resolving its import path, use that.
data := packageDataCache.Do(r.path, func() interface{} {
data := packageDataCache.Do(r.path, func() any {
loaded = true
var data packageData
if r.dir != "" {
@ -1063,7 +1063,7 @@ func cleanImport(path string) string {
var isDirCache par.Cache
func isDir(path string) bool {
return isDirCache.Do(path, func() interface{} {
return isDirCache.Do(path, func() any {
fi, err := fsys.Stat(path)
return err == nil && fi.IsDir()
}).(bool)
@ -1191,7 +1191,7 @@ var (
// goModPath returns the module path in the go.mod in dir, if any.
func goModPath(dir string) (path string) {
return goModPathCache.Do(dir, func() interface{} {
return goModPathCache.Do(dir, func() any {
data, err := os.ReadFile(filepath.Join(dir, "go.mod"))
if err != nil {
return ""
@ -2221,7 +2221,7 @@ func (p *Package) setBuildInfo() {
// executables always appear stale unless the user sets the same flags.
// Perhaps it's safe to omit those flags when GO_GCFLAGS and GO_LDFLAGS
// are not set?
setPkgErrorf := func(format string, args ...interface{}) {
setPkgErrorf := func(format string, args ...any) {
if p.Error == nil {
p.Error = &PackageError{Err: fmt.Errorf(format, args...)}
}
@ -2397,7 +2397,7 @@ func (p *Package) setBuildInfo() {
Status vcs.Status
Err error
}
cached := vcsStatusCache.Do(repoDir, func() interface{} {
cached := vcsStatusCache.Do(repoDir, func() any {
st, err := vcsCmd.Status(vcsCmd, repoDir)
return vcsStatusError{st, err}
}).(vcsStatusError)

View File

@ -75,8 +75,8 @@ type goVersionFlag struct {
v string
}
func (f *goVersionFlag) String() string { return f.v }
func (f *goVersionFlag) Get() interface{} { return f.v }
func (f *goVersionFlag) String() string { return f.v }
func (f *goVersionFlag) Get() any { return f.v }
func (f *goVersionFlag) Set(s string) error {
if s != "" {

View File

@ -204,7 +204,7 @@ func (r *cachingRepo) Versions(prefix string) ([]string, error) {
list []string
err error
}
c := r.cache.Do("versions:"+prefix, func() interface{} {
c := r.cache.Do("versions:"+prefix, func() any {
list, err := r.repo().Versions(prefix)
return cached{list, err}
}).(cached)
@ -221,7 +221,7 @@ type cachedInfo struct {
}
func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
c := r.cache.Do("stat:"+rev, func() interface{} {
c := r.cache.Do("stat:"+rev, func() any {
file, info, err := readDiskStat(r.path, rev)
if err == nil {
return cachedInfo{info, nil}
@ -233,7 +233,7 @@ func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
// then save the information under the proper version, for future use.
if info.Version != rev {
file, _ = CachePath(module.Version{Path: r.path, Version: info.Version}, "info")
r.cache.Do("stat:"+info.Version, func() interface{} {
r.cache.Do("stat:"+info.Version, func() any {
return cachedInfo{info, err}
})
}
@ -253,12 +253,12 @@ func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
}
func (r *cachingRepo) Latest() (*RevInfo, error) {
c := r.cache.Do("latest:", func() interface{} {
c := r.cache.Do("latest:", func() any {
info, err := r.repo().Latest()
// Save info for likely future Stat call.
if err == nil {
r.cache.Do("stat:"+info.Version, func() interface{} {
r.cache.Do("stat:"+info.Version, func() any {
return cachedInfo{info, err}
})
if file, _, err := readDiskStat(r.path, info.Version); err != nil {
@ -281,7 +281,7 @@ func (r *cachingRepo) GoMod(version string) ([]byte, error) {
text []byte
err error
}
c := r.cache.Do("gomod:"+version, func() interface{} {
c := r.cache.Do("gomod:"+version, func() any {
file, text, err := readDiskGoMod(r.path, version)
if err == nil {
// Note: readDiskGoMod already called checkGoMod.

View File

@ -228,7 +228,7 @@ var dirLock sync.Map
// It returns the standard output and, for a non-zero exit,
// a *RunError indicating the command, exit status, and standard error.
// Standard error is unavailable for commands that exit successfully.
func Run(dir string, cmdline ...interface{}) ([]byte, error) {
func Run(dir string, cmdline ...any) ([]byte, error) {
return RunWithStdin(dir, nil, cmdline...)
}
@ -236,7 +236,7 @@ func Run(dir string, cmdline ...interface{}) ([]byte, error) {
// See https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html.
var bashQuoter = strings.NewReplacer(`"`, `\"`, `$`, `\$`, "`", "\\`", `\`, `\\`)
func RunWithStdin(dir string, stdin io.Reader, cmdline ...interface{}) ([]byte, error) {
func RunWithStdin(dir string, stdin io.Reader, cmdline ...any) ([]byte, error) {
if dir != "" {
muIface, ok := dirLock.Load(dir)
if !ok {

View File

@ -56,7 +56,7 @@ func newGitRepoCached(remote string, localOK bool) (Repo, error) {
err error
}
c := gitRepoCache.Do(key{remote, localOK}, func() interface{} {
c := gitRepoCache.Do(key{remote, localOK}, func() any {
repo, err := newGitRepo(remote, localOK)
return cached{repo, err}
}).(cached)
@ -503,7 +503,7 @@ func (r *gitRepo) Stat(rev string) (*RevInfo, error) {
info *RevInfo
err error
}
c := r.statCache.Do(rev, func() interface{} {
c := r.statCache.Do(rev, func() any {
info, err := r.stat(rev)
return cached{info, err}
}).(cached)

View File

@ -38,7 +38,7 @@ type VCSError struct {
func (e *VCSError) Error() string { return e.Err.Error() }
func vcsErrorf(format string, a ...interface{}) error {
func vcsErrorf(format string, a ...any) error {
return &VCSError{Err: fmt.Errorf(format, a...)}
}
@ -51,7 +51,7 @@ func NewRepo(vcs, remote string) (Repo, error) {
repo Repo
err error
}
c := vcsRepoCache.Do(key{vcs, remote}, func() interface{} {
c := vcsRepoCache.Do(key{vcs, remote}, func() any {
repo, err := newVCSRepo(vcs, remote)
if err != nil {
err = &VCSError{err}

View File

@ -321,7 +321,7 @@ func (r *codeRepo) convert(info *codehost.RevInfo, statVers string) (*RevInfo, e
return ok
}
invalidf := func(format string, args ...interface{}) error {
invalidf := func(format string, args ...any) error {
return &module.ModuleError{
Path: r.modPath,
Err: &module.InvalidVersionError{
@ -1066,7 +1066,7 @@ func (fi dataFileInfo) Size() int64 { return int64(len(fi.f.data)) }
func (fi dataFileInfo) Mode() fs.FileMode { return 0644 }
func (fi dataFileInfo) ModTime() time.Time { return time.Time{} }
func (fi dataFileInfo) IsDir() bool { return false }
func (fi dataFileInfo) Sys() interface{} { return nil }
func (fi dataFileInfo) Sys() any { return nil }
// hasPathPrefix reports whether the path s begins with the
// elements in prefix.

View File

@ -48,7 +48,7 @@ func Download(ctx context.Context, mod module.Version) (dir string, err error) {
dir string
err error
}
c := downloadCache.Do(mod, func() interface{} {
c := downloadCache.Do(mod, func() any {
dir, err := download(ctx, mod)
if err != nil {
return cached{"", err}
@ -165,7 +165,7 @@ func DownloadZip(ctx context.Context, mod module.Version) (zipfile string, err e
zipfile string
err error
}
c := downloadZipCache.Do(mod, func() interface{} {
c := downloadZipCache.Do(mod, func() any {
zipfile, err := CachePath(mod, "zip")
if err != nil {
return cached{"", err}

View File

@ -196,7 +196,7 @@ func Lookup(proxy, path string) Repo {
type cached struct {
r Repo
}
c := lookupCache.Do(lookupCacheKey{proxy, path}, func() interface{} {
c := lookupCache.Do(lookupCacheKey{proxy, path}, func() any {
r := newCachingRepo(path, func() (Repo, error) {
r, err := lookup(proxy, path)
if err == nil && traceRepo {
@ -308,7 +308,7 @@ func newLoggingRepo(r Repo) *loggingRepo {
// defer logCall("hello %s", arg)()
//
// Note the final ().
func logCall(format string, args ...interface{}) func() {
func logCall(format string, args ...any) func() {
start := time.Now()
fmt.Fprintf(os.Stderr, "+++ %s\n", fmt.Sprintf(format, args...))
return func() {
@ -371,7 +371,7 @@ type notExistError struct {
err error
}
func notExistErrorf(format string, args ...interface{}) error {
func notExistErrorf(format string, args ...any) error {
return notExistError{fmt.Errorf(format, args...)}
}

View File

@ -601,7 +601,7 @@ func (r *resolver) matchInModule(ctx context.Context, pattern string, m module.V
err error
}
e := r.matchInModuleCache.Do(key{pattern, m}, func() interface{} {
e := r.matchInModuleCache.Do(key{pattern, m}, func() any {
match := modload.MatchInModule(ctx, pattern, m, imports.AnyTags())
if len(match.Errs) > 0 {
return entry{match.Pkgs, match.Errs[0]}
@ -893,7 +893,7 @@ func (r *resolver) checkWildcardVersions(ctx context.Context) {
// curM at its original version contains a path matching q.pattern,
// but at rev.Version it does not, so (somewhat paradoxically) if
// we changed the version of curM it would no longer match the query.
var version interface{} = m
var version any = m
if rev.Version != q.version {
version = fmt.Sprintf("%s@%s (%s)", m.Path, q.version, m.Version)
}

View File

@ -326,7 +326,7 @@ func readModGraph(ctx context.Context, pruning modPruning, roots []module.Versio
// It does not load the transitive requirements of m even if the go version in
// m's go.mod file indicates that it supports graph pruning.
loadOne := func(m module.Version) (*modFileSummary, error) {
cached := mg.loadCache.Do(m, func() interface{} {
cached := mg.loadCache.Do(m, func() any {
summary, err := goModSummary(m)
mu.Lock()

View File

@ -612,7 +612,7 @@ func dirInModule(path, mpath, mdir string, isLocal bool) (dir string, haveGoFile
// (the main module, and any directory trees pointed at by replace directives).
if isLocal {
for d := dir; d != mdir && len(d) > len(mdir); {
haveGoMod := haveGoModCache.Do(d, func() interface{} {
haveGoMod := haveGoModCache.Do(d, func() any {
fi, err := fsys.Stat(filepath.Join(d, "go.mod"))
return err == nil && !fi.IsDir()
}).(bool)
@ -635,7 +635,7 @@ func dirInModule(path, mpath, mdir string, isLocal bool) (dir string, haveGoFile
// Are there Go source files in the directory?
// We don't care about build tags, not even "+build ignore".
// We're just looking for a plausible directory.
res := haveGoFilesCache.Do(dir, func() interface{} {
res := haveGoFilesCache.Do(dir, func() any {
ok, err := fsys.IsDirWithGoFiles(dir)
return goFilesEntry{haveGoFiles: ok, err: err}
}).(goFilesEntry)

View File

@ -859,7 +859,7 @@ func (ld *loader) reset() {
// errorf reports an error via either os.Stderr or base.Errorf,
// according to whether ld.AllowErrors is set.
func (ld *loader) errorf(format string, args ...interface{}) {
func (ld *loader) errorf(format string, args ...any) {
if ld.AllowErrors {
fmt.Fprintf(os.Stderr, format, args...)
} else {
@ -1492,7 +1492,7 @@ func (ld *loader) pkg(ctx context.Context, path string, flags loadPkgFlags) *loa
panic("internal error: (*loader).pkg called with pkgImportsLoaded flag set")
}
pkg := ld.pkgCache.Do(path, func() interface{} {
pkg := ld.pkgCache.Do(path, func() any {
pkg := &loadPkg{
path: path,
}

View File

@ -664,7 +664,7 @@ func rawGoModSummary(m module.Version) (*modFileSummary, error) {
summary *modFileSummary
err error
}
c := rawGoModSummaryCache.Do(key{m}, func() interface{} {
c := rawGoModSummaryCache.Do(key{m}, func() any {
summary := new(modFileSummary)
name, data, err := rawGoModData(m)
if err != nil {
@ -766,7 +766,7 @@ func queryLatestVersionIgnoringRetractions(ctx context.Context, path string) (la
latest module.Version
err error
}
e := latestVersionIgnoringRetractionsCache.Do(path, func() interface{} {
e := latestVersionIgnoringRetractionsCache.Do(path, func() any {
ctx, span := trace.StartSpan(ctx, "queryLatestVersionIgnoringRetractions "+path)
defer span.Done()

View File

@ -147,7 +147,7 @@ func checkVendorConsistency(index *modFileIndex, modFile *modfile.File) {
}
vendErrors := new(strings.Builder)
vendErrorf := func(mod module.Version, format string, args ...interface{}) {
vendErrorf := func(mod module.Version, format string, args ...any) {
detail := fmt.Sprintf(format, args...)
if mod.Version == "" {
fmt.Fprintf(vendErrors, "\n\t%s: %s", mod.Path, detail)

View File

@ -114,7 +114,7 @@ func buildList(targets []module.Version, reqs Reqs, upgrade func(module.Version)
for _, target := range targets {
work.Add(target)
}
work.Do(10, func(item interface{}) {
work.Do(10, func(item any) {
m := item.(module.Version)
var required []module.Version

View File

@ -14,24 +14,24 @@ import (
// Work manages a set of work items to be executed in parallel, at most once each.
// The items in the set must all be valid map keys.
type Work struct {
f func(interface{}) // function to run for each item
running int // total number of runners
f func(any) // function to run for each item
running int // total number of runners
mu sync.Mutex
added map[interface{}]bool // items added to set
todo []interface{} // items yet to be run
wait sync.Cond // wait when todo is empty
waiting int // number of runners waiting for todo
added map[any]bool // items added to set
todo []any // items yet to be run
wait sync.Cond // wait when todo is empty
waiting int // number of runners waiting for todo
}
func (w *Work) init() {
if w.added == nil {
w.added = make(map[interface{}]bool)
w.added = make(map[any]bool)
}
}
// Add adds item to the work set, if it hasn't already been added.
func (w *Work) Add(item interface{}) {
func (w *Work) Add(item any) {
w.mu.Lock()
w.init()
if !w.added[item] {
@ -51,7 +51,7 @@ func (w *Work) Add(item interface{}) {
// before calling Do (or else Do returns immediately),
// but it is allowed for f(item) to add new items to the set.
// Do should only be used once on a given Work.
func (w *Work) Do(n int, f func(item interface{})) {
func (w *Work) Do(n int, f func(item any)) {
if n < 1 {
panic("par.Work.Do: n < 1")
}
@ -110,13 +110,13 @@ type Cache struct {
type cacheEntry struct {
done uint32
mu sync.Mutex
result interface{}
result any
}
// Do calls the function f if and only if Do is being called for the first time with this key.
// No call to Do with a given key returns until the one call to f returns.
// Do returns the value returned by the one call to f.
func (c *Cache) Do(key interface{}, f func() interface{}) interface{} {
func (c *Cache) Do(key any, f func() any) any {
entryIface, ok := c.m.Load(key)
if !ok {
entryIface, _ = c.m.LoadOrStore(key, new(cacheEntry))
@ -136,7 +136,7 @@ func (c *Cache) Do(key interface{}, f func() interface{}) interface{} {
// Get returns the cached result associated with key.
// It returns nil if there is no such result.
// If the result for key is being computed, Get does not wait for the computation to finish.
func (c *Cache) Get(key interface{}) interface{} {
func (c *Cache) Get(key any) any {
entryIface, ok := c.m.Load(key)
if !ok {
return nil
@ -156,7 +156,7 @@ func (c *Cache) Get(key interface{}) interface{} {
// TODO(jayconrod): Delete this after the package cache clearing functions
// in internal/load have been removed.
func (c *Cache) Clear() {
c.m.Range(func(key, value interface{}) bool {
c.m.Range(func(key, value any) bool {
c.m.Delete(key)
return true
})
@ -169,7 +169,7 @@ func (c *Cache) Clear() {
//
// TODO(jayconrod): Delete this after the package cache clearing functions
// in internal/load have been removed.
func (c *Cache) Delete(key interface{}) {
func (c *Cache) Delete(key any) {
c.m.Delete(key)
}
@ -180,8 +180,8 @@ func (c *Cache) Delete(key interface{}) {
//
// TODO(jayconrod): Delete this after the package cache clearing functions
// in internal/load have been removed.
func (c *Cache) DeleteIf(pred func(key interface{}) bool) {
c.m.Range(func(key, _ interface{}) bool {
func (c *Cache) DeleteIf(pred func(key any) bool) {
c.m.Range(func(key, _ any) bool {
if pred(key) {
c.Delete(key)
}

View File

@ -16,7 +16,7 @@ func TestWork(t *testing.T) {
const N = 10000
n := int32(0)
w.Add(N)
w.Do(100, func(x interface{}) {
w.Do(100, func(x any) {
atomic.AddInt32(&n, 1)
i := x.(int)
if i >= 2 {
@ -40,7 +40,7 @@ func TestWorkParallel(t *testing.T) {
}
start := time.Now()
var n int32
w.Do(N, func(x interface{}) {
w.Do(N, func(x any) {
time.Sleep(1 * time.Millisecond)
atomic.AddInt32(&n, +1)
})
@ -58,19 +58,19 @@ func TestCache(t *testing.T) {
var cache Cache
n := 1
v := cache.Do(1, func() interface{} { n++; return n })
v := cache.Do(1, func() any { n++; return n })
if v != 2 {
t.Fatalf("cache.Do(1) did not run f")
}
v = cache.Do(1, func() interface{} { n++; return n })
v = cache.Do(1, func() any { n++; return n })
if v != 2 {
t.Fatalf("cache.Do(1) ran f again!")
}
v = cache.Do(2, func() interface{} { n++; return n })
v = cache.Do(2, func() any { n++; return n })
if v != 3 {
t.Fatalf("cache.Do(2) did not run f")
}
v = cache.Do(1, func() interface{} { n++; return n })
v = cache.Do(1, func() any { n++; return n })
if v != 2 {
t.Fatalf("cache.Do(1) did not returned saved value from original cache.Do(1)")
}

View File

@ -69,7 +69,7 @@ func init() {
CmdRun.Flag.Var((*base.StringsFlag)(&work.ExecCmd), "exec", "")
}
func printStderr(args ...interface{}) (int, error) {
func printStderr(args ...any) (int, error) {
return fmt.Fprint(os.Stderr, args...)
}

View File

@ -14,7 +14,7 @@ import (
// StringList flattens its arguments into a single []string.
// Each argument in args must have type string or []string.
func StringList(args ...interface{}) []string {
func StringList(args ...any) []string {
var x []string
for _, arg := range args {
switch arg := arg.(type) {

View File

@ -1311,7 +1311,7 @@ func metaImportsForPrefix(importPrefix string, mod ModuleMode, security web.Secu
return res, nil
}
resi, _, _ := fetchGroup.Do(importPrefix, func() (resi interface{}, err error) {
resi, _, _ := fetchGroup.Do(importPrefix, func() (resi any, err error) {
fetchCacheMu.Lock()
if res, ok := fetchCache[importPrefix]; ok {
fetchCacheMu.Unlock()
@ -1588,7 +1588,7 @@ type importError struct {
err error
}
func importErrorf(path, format string, args ...interface{}) error {
func importErrorf(path, format string, args ...any) error {
err := &importError{importPath: path, err: fmt.Errorf(format, args...)}
if errStr := err.Error(); !strings.Contains(errStr, path) {
panic(fmt.Sprintf("path %q not in error %q", path, errStr))

View File

@ -37,7 +37,7 @@ type Builder struct {
actionCache map[cacheKey]*Action // a cache of already-constructed actions
mkdirCache map[string]bool // a cache of created directories
flagCache map[[2]string]bool // a cache of supported compiler flags
Print func(args ...interface{}) (int, error)
Print func(args ...any) (int, error)
IsCmdList bool // running as part of go list; set p.Stale and additional fields below
NeedError bool // list needs p.Error
@ -120,8 +120,8 @@ type actionQueue []*Action
func (q *actionQueue) Len() int { return len(*q) }
func (q *actionQueue) Swap(i, j int) { (*q)[i], (*q)[j] = (*q)[j], (*q)[i] }
func (q *actionQueue) Less(i, j int) bool { return (*q)[i].priority < (*q)[j].priority }
func (q *actionQueue) Push(x interface{}) { *q = append(*q, x.(*Action)) }
func (q *actionQueue) Pop() interface{} {
func (q *actionQueue) Push(x any) { *q = append(*q, x.(*Action)) }
func (q *actionQueue) Pop() any {
n := len(*q) - 1
x := (*q)[n]
*q = (*q)[:n]
@ -241,7 +241,7 @@ const (
)
func (b *Builder) Init() {
b.Print = func(a ...interface{}) (int, error) {
b.Print = func(a ...any) (int, error) {
return fmt.Fprint(os.Stderr, a...)
}
b.actionCache = make(map[cacheKey]*Action)

View File

@ -234,7 +234,7 @@ func TestRespectSetgidDir(t *testing.T) {
// of `(*Builder).ShowCmd` afterwards as a sanity check.
cfg.BuildX = true
var cmdBuf bytes.Buffer
b.Print = func(a ...interface{}) (int, error) {
b.Print = func(a ...any) (int, error) {
return cmdBuf.WriteString(fmt.Sprint(a...))
}

View File

@ -1948,7 +1948,7 @@ func mayberemovefile(s string) {
// fmtcmd replaces the name of the current directory with dot (.)
// but only when it is at the beginning of a space-separated token.
//
func (b *Builder) fmtcmd(dir string, format string, args ...interface{}) string {
func (b *Builder) fmtcmd(dir string, format string, args ...any) string {
cmd := fmt.Sprintf(format, args...)
if dir != "" && dir != "/" {
dot := " ."
@ -1974,7 +1974,7 @@ func (b *Builder) fmtcmd(dir string, format string, args ...interface{}) string
// showcmd prints the given command to standard output
// for the implementation of -n or -x.
func (b *Builder) Showcmd(dir string, format string, args ...interface{}) {
func (b *Builder) Showcmd(dir string, format string, args ...any) {
b.output.Lock()
defer b.output.Unlock()
b.Print(b.fmtcmd(dir, format, args...) + "\n")
@ -2038,7 +2038,7 @@ var cgoTypeSigRe = lazyregexp.New(`\b_C2?(type|func|var|macro)_\B`)
// run runs the command given by cmdline in the directory dir.
// If the command fails, run prints information about the failure
// and returns a non-nil error.
func (b *Builder) run(a *Action, dir string, desc string, env []string, cmdargs ...interface{}) error {
func (b *Builder) run(a *Action, dir string, desc string, env []string, cmdargs ...any) error {
out, err := b.runOut(a, dir, env, cmdargs...)
if len(out) > 0 {
if desc == "" {
@ -2072,7 +2072,7 @@ func (b *Builder) processOutput(out []byte) string {
// runOut runs the command given by cmdline in the directory dir.
// It returns the command output and any errors that occurred.
// It accumulates execution time in a.
func (b *Builder) runOut(a *Action, dir string, env []string, cmdargs ...interface{}) ([]byte, error) {
func (b *Builder) runOut(a *Action, dir string, env []string, cmdargs ...any) ([]byte, error) {
cmdline := str.StringList(cmdargs...)
for _, arg := range cmdline {
@ -2409,7 +2409,7 @@ func (b *Builder) gccld(a *Action, p *load.Package, objdir, outfile string, flag
cmd = b.GccCmd(p.Dir, objdir)
}
cmdargs := []interface{}{cmd, "-o", outfile, objs, flags}
cmdargs := []any{cmd, "-o", outfile, objs, flags}
dir := p.Dir
out, err := b.runOut(a, base.Cwd(), b.cCompilerEnv(), cmdargs...)

View File

@ -165,7 +165,7 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg, embedcfg
gcflags = append(gcflags, fmt.Sprintf("-c=%d", c))
}
args := []interface{}{cfg.BuildToolexec, base.Tool("compile"), "-o", ofile, "-trimpath", a.trimpath(), defaultGcFlags, gcflags}
args := []any{cfg.BuildToolexec, base.Tool("compile"), "-o", ofile, "-trimpath", a.trimpath(), defaultGcFlags, gcflags}
if p.Internal.LocalPrefix == "" {
args = append(args, "-nolocalimports")
} else {
@ -362,11 +362,11 @@ func (a *Action) trimpath() string {
return rewrite
}
func asmArgs(a *Action, p *load.Package) []interface{} {
func asmArgs(a *Action, p *load.Package) []any {
// Add -I pkg/GOOS_GOARCH so #include "textflag.h" works in .s files.
inc := filepath.Join(cfg.GOROOT, "pkg", "include")
pkgpath := pkgPath(a)
args := []interface{}{cfg.BuildToolexec, base.Tool("asm"), "-p", pkgpath, "-trimpath", a.trimpath(), "-I", a.Objdir, "-I", inc, "-D", "GOOS_" + cfg.Goos, "-D", "GOARCH_" + cfg.Goarch, forcedAsmflags, p.Internal.Asmflags}
args := []any{cfg.BuildToolexec, base.Tool("asm"), "-p", pkgpath, "-trimpath", a.trimpath(), "-I", a.Objdir, "-I", inc, "-D", "GOOS_" + cfg.Goos, "-D", "GOARCH_" + cfg.Goarch, forcedAsmflags, p.Internal.Asmflags}
if p.ImportPath == "runtime" && cfg.Goarch == "386" {
for _, arg := range forcedAsmflags {
if arg == "-dynlink" {
@ -455,8 +455,8 @@ func (gcToolchain) symabis(b *Builder, a *Action, sfiles []string) (string, erro
// toolVerify checks that the command line args writes the same output file
// if run using newTool instead.
// Unused now but kept around for future use.
func toolVerify(a *Action, b *Builder, p *load.Package, newTool string, ofile string, args []interface{}) error {
newArgs := make([]interface{}, len(args))
func toolVerify(a *Action, b *Builder, p *load.Package, newTool string, ofile string, args []any) error {
newArgs := make([]any, len(args))
copy(newArgs, args)
newArgs[1] = base.Tool(newTool)
newArgs[3] = ofile + ".new" // x.6 becomes x.6.new

View File

@ -357,7 +357,7 @@ func proxyHandler(w http.ResponseWriter, r *http.Request) {
zip []byte
err error
}
c := zipCache.Do(a, func() interface{} {
c := zipCache.Do(a, func() any {
var buf bytes.Buffer
z := zip.NewWriter(&buf)
for _, f := range a.Files {
@ -431,7 +431,7 @@ func readArchive(path, vers string) (*txtar.Archive, error) {
prefix := strings.ReplaceAll(enc, "/", "_")
name := filepath.Join(cmdGoDir, "testdata/mod", prefix+"_"+encVers+".txt")
a := archiveCache.Do(name, func() interface{} {
a := archiveCache.Do(name, func() any {
a, err := txtar.ParseFile(name)
if err != nil {
if testing.Verbose() || !os.IsNotExist(err) {

View File

@ -375,7 +375,7 @@ Script:
default:
if strings.HasPrefix(cond.tag, "exec:") {
prog := cond.tag[len("exec:"):]
ok = execCache.Do(prog, func() interface{} {
ok = execCache.Do(prog, func() any {
if runtime.GOOS == "plan9" && prog == "git" {
// The Git command is usually not the real Git on Plan 9.
// See https://golang.org/issues/29640.
@ -1310,7 +1310,7 @@ func (ts *testScript) expand(s string, inRegexp bool) string {
}
// fatalf aborts the test with the given failure message.
func (ts *testScript) fatalf(format string, args ...interface{}) {
func (ts *testScript) fatalf(format string, args ...any) {
fmt.Fprintf(&ts.log, "FAIL: %s:%d: %s\n", ts.file, ts.lineno, fmt.Sprintf(format, args...))
ts.t.FailNow()
}

View File

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
// Addmod adds a module as a txtar archive to the testdata/mod directory.
@ -39,7 +40,7 @@ func usage() {
var tmpdir string
func fatalf(format string, args ...interface{}) {
func fatalf(format string, args ...any) {
os.RemoveAll(tmpdir)
log.Fatalf(format, args...)
}

View File

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
// Savedir archives a directory tree as a txtar archive printed to standard output.

View File

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build linux
// +build linux
// This test is run by src/cmd/dist/test.go (cmd_go_test_terminal),

View File

@ -183,7 +183,7 @@ func (r *reporter) getState() *reporterState {
// Warnf emits a warning message to the reporter's error stream,
// without changing its exit code.
func (r *reporter) Warnf(format string, args ...interface{}) {
func (r *reporter) Warnf(format string, args ...any) {
fmt.Fprintf(r.getState().err, format, args...)
}

View File

@ -103,7 +103,7 @@ func TestFindAndHash(t *testing.T) {
id[i] = byte(i)
}
numError := 0
errorf := func(msg string, args ...interface{}) {
errorf := func(msg string, args ...any) {
t.Errorf(msg, args...)
if numError++; numError > 20 {
t.Logf("stopping after too many errors")

View File

@ -151,7 +151,7 @@ func (r *excludedReader) Read(p []byte) (int, error) {
return n, err
}
func findMachoCodeSignature(r interface{}) (*macho.File, codesign.CodeSigCmd, bool) {
func findMachoCodeSignature(r any) (*macho.File, codesign.CodeSigCmd, bool) {
ra, ok := r.(io.ReaderAt)
if !ok {
return nil, codesign.CodeSigCmd{}, false

View File

@ -145,7 +145,7 @@ func writeAndKill(w io.Writer, b []byte) {
// and fails the test with a useful message if they don't match.
func diffJSON(t *testing.T, have, want []byte) {
t.Helper()
type event map[string]interface{}
type event map[string]any
// Parse into events, one per line.
parseEvents := func(b []byte) ([]event, []string) {

View File

@ -16,20 +16,20 @@ type Data struct {
}
type Event struct {
Name string `json:"name,omitempty"`
Phase string `json:"ph"`
Scope string `json:"s,omitempty"`
Time float64 `json:"ts"`
Dur float64 `json:"dur,omitempty"`
PID uint64 `json:"pid"`
TID uint64 `json:"tid"`
ID uint64 `json:"id,omitempty"`
BindPoint string `json:"bp,omitempty"`
Stack int `json:"sf,omitempty"`
EndStack int `json:"esf,omitempty"`
Arg interface{} `json:"args,omitempty"`
Cname string `json:"cname,omitempty"`
Category string `json:"cat,omitempty"`
Name string `json:"name,omitempty"`
Phase string `json:"ph"`
Scope string `json:"s,omitempty"`
Time float64 `json:"ts"`
Dur float64 `json:"dur,omitempty"`
PID uint64 `json:"pid"`
TID uint64 `json:"tid"`
ID uint64 `json:"id,omitempty"`
BindPoint string `json:"bp,omitempty"`
Stack int `json:"sf,omitempty"`
EndStack int `json:"esf,omitempty"`
Arg any `json:"args,omitempty"`
Cname string `json:"cname,omitempty"`
Category string `json:"cat,omitempty"`
}
type Frame struct {

View File

@ -93,7 +93,7 @@ func main() {
var exitCode = 0
func errorf(format string, args ...interface{}) {
func errorf(format string, args ...any) {
log.Printf(format, args...)
exitCode = 1
}

View File

@ -203,7 +203,7 @@ func TestLargeDefs(t *testing.T) {
}
b := bufio.NewWriter(f)
printf := func(format string, args ...interface{}) {
printf := func(format string, args ...any) {
_, err := fmt.Fprintf(b, format, args...)
if err != nil {
t.Fatalf("Writing to %s: %v", large, err)
@ -454,7 +454,7 @@ func (f *FakeFile) IsDir() bool {
return false
}
func (f *FakeFile) Sys() interface{} {
func (f *FakeFile) Sys() any {
return nil
}

View File

@ -69,18 +69,18 @@ func (r *readlineUI) ReadLine(prompt string) (string, error) {
// It formats the text as fmt.Print would and adds a final \n if not already present.
// For line-based UI, Print writes to standard error.
// (Standard output is reserved for report data.)
func (r *readlineUI) Print(args ...interface{}) {
func (r *readlineUI) Print(args ...any) {
r.print(false, args...)
}
// PrintErr shows an error message to the user.
// It formats the text as fmt.Print would and adds a final \n if not already present.
// For line-based UI, PrintErr writes to standard error.
func (r *readlineUI) PrintErr(args ...interface{}) {
func (r *readlineUI) PrintErr(args ...any) {
r.print(true, args...)
}
func (r *readlineUI) print(withColor bool, args ...interface{}) {
func (r *readlineUI) print(withColor bool, args ...any) {
text := fmt.Sprint(args...)
if !strings.HasSuffix(text, "\n") {
text += "\n"

View File

@ -206,7 +206,7 @@ var templMain = template.Must(template.New("").Parse(`
</html>
`))
func dief(msg string, args ...interface{}) {
func dief(msg string, args ...any) {
fmt.Fprintf(os.Stderr, msg, args...)
os.Exit(1)
}

View File

@ -155,7 +155,7 @@ func httpMMUPlot(w http.ResponseWriter, r *http.Request) {
}
// Create JSON response.
err = json.NewEncoder(w).Encode(map[string]interface{}{"xMin": int64(xMin), "xMax": int64(xMax), "quantiles": quantiles, "curve": plot})
err = json.NewEncoder(w).Encode(map[string]any{"xMin": int64(xMin), "xMax": int64(xMax), "quantiles": quantiles, "curve": plot})
if err != nil {
log.Printf("failed to serialize response: %v", err)
return

View File

@ -1054,7 +1054,7 @@ func (ctx *traceContext) emitInstant(ev *trace.Event, name, category string) {
cname = colorLightGrey
}
}
var arg interface{}
var arg any
if ev.Type == trace.EvProcStart {
type Arg struct {
ThreadID uint64

View File

@ -17,13 +17,13 @@ func (h IntHeap) Len() int { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) {
func (h *IntHeap) Push(x any) {
// Push and Pop use pointer receivers because they modify the slice's length,
// not just its contents.
*h = append(*h, x.(int))
}
func (h *IntHeap) Pop() interface{} {
func (h *IntHeap) Pop() any {
old := *h
n := len(old)
x := old[n-1]

View File

@ -34,14 +34,14 @@ func (pq PriorityQueue) Swap(i, j int) {
pq[j].index = j
}
func (pq *PriorityQueue) Push(x interface{}) {
func (pq *PriorityQueue) Push(x any) {
n := len(*pq)
item := x.(*Item)
item.index = n
*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
func (pq *PriorityQueue) Pop() any {
old := *pq
n := len(old)
item := old[n-1]

View File

@ -31,8 +31,8 @@ import "sort"
// use heap.Push and heap.Pop.
type Interface interface {
sort.Interface
Push(x interface{}) // add x as element Len()
Pop() interface{} // remove and return element Len() - 1.
Push(x any) // add x as element Len()
Pop() any // remove and return element Len() - 1.
}
// Init establishes the heap invariants required by the other routines in this package.
@ -49,7 +49,7 @@ func Init(h Interface) {
// Push pushes the element x onto the heap.
// The complexity is O(log n) where n = h.Len().
func Push(h Interface, x interface{}) {
func Push(h Interface, x any) {
h.Push(x)
up(h, h.Len()-1)
}
@ -57,7 +57,7 @@ func Push(h Interface, x interface{}) {
// Pop removes and returns the minimum element (according to Less) from the heap.
// The complexity is O(log n) where n = h.Len().
// Pop is equivalent to Remove(h, 0).
func Pop(h Interface) interface{} {
func Pop(h Interface) any {
n := h.Len() - 1
h.Swap(0, n)
down(h, 0, n)
@ -66,7 +66,7 @@ func Pop(h Interface) interface{} {
// Remove removes and returns the element at index i from the heap.
// The complexity is O(log n) where n = h.Len().
func Remove(h Interface, i int) interface{} {
func Remove(h Interface, i int) any {
n := h.Len() - 1
if n != i {
h.Swap(i, n)

View File

@ -23,12 +23,12 @@ func (h *myHeap) Len() int {
return len(*h)
}
func (h *myHeap) Pop() (v interface{}) {
func (h *myHeap) Pop() (v any) {
*h, v = (*h)[:h.Len()-1], (*h)[h.Len()-1]
return
}
func (h *myHeap) Push(v interface{}) {
func (h *myHeap) Push(v any) {
*h = append(*h, v.(int))
}

View File

@ -24,7 +24,7 @@ type Element struct {
list *List
// The value stored with this element.
Value interface{}
Value any
}
// Next returns the next list element or nil.
@ -100,7 +100,7 @@ func (l *List) insert(e, at *Element) *Element {
}
// insertValue is a convenience wrapper for insert(&Element{Value: v}, at).
func (l *List) insertValue(v interface{}, at *Element) *Element {
func (l *List) insertValue(v any, at *Element) *Element {
return l.insert(&Element{Value: v}, at)
}
@ -131,7 +131,7 @@ func (l *List) move(e, at *Element) {
// Remove removes e from l if e is an element of list l.
// It returns the element value e.Value.
// The element must not be nil.
func (l *List) Remove(e *Element) interface{} {
func (l *List) Remove(e *Element) any {
if e.list == l {
// if e.list == l, l must have been initialized when e was inserted
// in l or l == nil (e is a zero Element) and l.remove will crash
@ -141,13 +141,13 @@ func (l *List) Remove(e *Element) interface{} {
}
// PushFront inserts a new element e with value v at the front of list l and returns e.
func (l *List) PushFront(v interface{}) *Element {
func (l *List) PushFront(v any) *Element {
l.lazyInit()
return l.insertValue(v, &l.root)
}
// PushBack inserts a new element e with value v at the back of list l and returns e.
func (l *List) PushBack(v interface{}) *Element {
func (l *List) PushBack(v any) *Element {
l.lazyInit()
return l.insertValue(v, l.root.prev)
}
@ -155,7 +155,7 @@ func (l *List) PushBack(v interface{}) *Element {
// InsertBefore inserts a new element e with value v immediately before mark and returns e.
// If mark is not an element of l, the list is not modified.
// The mark must not be nil.
func (l *List) InsertBefore(v interface{}, mark *Element) *Element {
func (l *List) InsertBefore(v any, mark *Element) *Element {
if mark.list != l {
return nil
}
@ -166,7 +166,7 @@ func (l *List) InsertBefore(v interface{}, mark *Element) *Element {
// InsertAfter inserts a new element e with value v immediately after mark and returns e.
// If mark is not an element of l, the list is not modified.
// The mark must not be nil.
func (l *List) InsertAfter(v interface{}, mark *Element) *Element {
func (l *List) InsertAfter(v any, mark *Element) *Element {
if mark.list != l {
return nil
}

View File

@ -141,7 +141,7 @@ func TestList(t *testing.T) {
checkListPointers(t, l, []*Element{})
}
func checkList(t *testing.T, l *List, es []interface{}) {
func checkList(t *testing.T, l *List, es []any) {
if !checkListLen(t, l, len(es)) {
return
}
@ -169,36 +169,36 @@ func TestExtending(t *testing.T) {
l3 := New()
l3.PushBackList(l1)
checkList(t, l3, []interface{}{1, 2, 3})
checkList(t, l3, []any{1, 2, 3})
l3.PushBackList(l2)
checkList(t, l3, []interface{}{1, 2, 3, 4, 5})
checkList(t, l3, []any{1, 2, 3, 4, 5})
l3 = New()
l3.PushFrontList(l2)
checkList(t, l3, []interface{}{4, 5})
checkList(t, l3, []any{4, 5})
l3.PushFrontList(l1)
checkList(t, l3, []interface{}{1, 2, 3, 4, 5})
checkList(t, l3, []any{1, 2, 3, 4, 5})
checkList(t, l1, []interface{}{1, 2, 3})
checkList(t, l2, []interface{}{4, 5})
checkList(t, l1, []any{1, 2, 3})
checkList(t, l2, []any{4, 5})
l3 = New()
l3.PushBackList(l1)
checkList(t, l3, []interface{}{1, 2, 3})
checkList(t, l3, []any{1, 2, 3})
l3.PushBackList(l3)
checkList(t, l3, []interface{}{1, 2, 3, 1, 2, 3})
checkList(t, l3, []any{1, 2, 3, 1, 2, 3})
l3 = New()
l3.PushFrontList(l1)
checkList(t, l3, []interface{}{1, 2, 3})
checkList(t, l3, []any{1, 2, 3})
l3.PushFrontList(l3)
checkList(t, l3, []interface{}{1, 2, 3, 1, 2, 3})
checkList(t, l3, []any{1, 2, 3, 1, 2, 3})
l3 = New()
l1.PushBackList(l3)
checkList(t, l1, []interface{}{1, 2, 3})
checkList(t, l1, []any{1, 2, 3})
l1.PushFrontList(l3)
checkList(t, l1, []interface{}{1, 2, 3})
checkList(t, l1, []any{1, 2, 3})
}
func TestRemove(t *testing.T) {
@ -289,19 +289,19 @@ func TestMove(t *testing.T) {
func TestZeroList(t *testing.T) {
var l1 = new(List)
l1.PushFront(1)
checkList(t, l1, []interface{}{1})
checkList(t, l1, []any{1})
var l2 = new(List)
l2.PushBack(1)
checkList(t, l2, []interface{}{1})
checkList(t, l2, []any{1})
var l3 = new(List)
l3.PushFrontList(l1)
checkList(t, l3, []interface{}{1})
checkList(t, l3, []any{1})
var l4 = new(List)
l4.PushBackList(l2)
checkList(t, l4, []interface{}{1})
checkList(t, l4, []any{1})
}
// Test that a list l is not modified when calling InsertBefore with a mark that is not an element of l.
@ -311,7 +311,7 @@ func TestInsertBeforeUnknownMark(t *testing.T) {
l.PushBack(2)
l.PushBack(3)
l.InsertBefore(1, new(Element))
checkList(t, &l, []interface{}{1, 2, 3})
checkList(t, &l, []any{1, 2, 3})
}
// Test that a list l is not modified when calling InsertAfter with a mark that is not an element of l.
@ -321,7 +321,7 @@ func TestInsertAfterUnknownMark(t *testing.T) {
l.PushBack(2)
l.PushBack(3)
l.InsertAfter(1, new(Element))
checkList(t, &l, []interface{}{1, 2, 3})
checkList(t, &l, []any{1, 2, 3})
}
// Test that a list l is not modified when calling MoveAfter or MoveBefore with a mark that is not an element of l.
@ -333,10 +333,10 @@ func TestMoveUnknownMark(t *testing.T) {
e2 := l2.PushBack(2)
l1.MoveAfter(e1, e2)
checkList(t, &l1, []interface{}{1})
checkList(t, &l2, []interface{}{2})
checkList(t, &l1, []any{1})
checkList(t, &l2, []any{2})
l1.MoveBefore(e1, e2)
checkList(t, &l1, []interface{}{1})
checkList(t, &l2, []interface{}{2})
checkList(t, &l1, []any{1})
checkList(t, &l2, []any{2})
}

View File

@ -88,7 +88,7 @@ func ExampleRing_Do() {
}
// Iterate through the ring and print its contents
r.Do(func(p interface{}) {
r.Do(func(p any) {
fmt.Println(p.(int))
})
@ -117,7 +117,7 @@ func ExampleRing_Move() {
r = r.Move(3)
// Iterate through the ring and print its contents
r.Do(func(p interface{}) {
r.Do(func(p any) {
fmt.Println(p.(int))
})
@ -154,7 +154,7 @@ func ExampleRing_Link() {
rs := r.Link(s)
// Iterate through the combined ring and print its contents
rs.Do(func(p interface{}) {
rs.Do(func(p any) {
fmt.Println(p.(int))
})
@ -182,7 +182,7 @@ func ExampleRing_Unlink() {
r.Unlink(3)
// Iterate through the remaining ring and print its contents
r.Do(func(p interface{}) {
r.Do(func(p any) {
fmt.Println(p.(int))
})

View File

@ -13,7 +13,7 @@ package ring
//
type Ring struct {
next, prev *Ring
Value interface{} // for use by client; untouched by this library
Value any // for use by client; untouched by this library
}
func (r *Ring) init() *Ring {
@ -131,7 +131,7 @@ func (r *Ring) Len() int {
// Do calls function f on each element of the ring, in forward order.
// The behavior of Do is undefined if f changes *r.
func (r *Ring) Do(f func(interface{})) {
func (r *Ring) Do(f func(any)) {
if r != nil {
f(r.Value)
for p := r.Next(); p != r; p = p.next {

View File

@ -33,7 +33,7 @@ func verify(t *testing.T, r *Ring, N int, sum int) {
// iteration
n = 0
s := 0
r.Do(func(p interface{}) {
r.Do(func(p any) {
n++
if p != nil {
s += p.(int)

View File

@ -150,7 +150,7 @@ type Context interface {
// u, ok := ctx.Value(userKey).(*User)
// return u, ok
// }
Value(key interface{}) interface{}
Value(key any) any
}
// Canceled is the error returned by Context.Err when the context is canceled.
@ -182,7 +182,7 @@ func (*emptyCtx) Err() error {
return nil
}
func (*emptyCtx) Value(key interface{}) interface{} {
func (*emptyCtx) Value(key any) any {
return nil
}
@ -348,7 +348,7 @@ type cancelCtx struct {
err error // set to non-nil by the first cancel call
}
func (c *cancelCtx) Value(key interface{}) interface{} {
func (c *cancelCtx) Value(key any) any {
if key == &cancelCtxKey {
return c
}
@ -520,7 +520,7 @@ func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
// interface{}, context keys often have concrete type
// struct{}. Alternatively, exported context key variables' static
// type should be a pointer or interface.
func WithValue(parent Context, key, val interface{}) Context {
func WithValue(parent Context, key, val any) Context {
if parent == nil {
panic("cannot create context from nil parent")
}
@ -537,13 +537,13 @@ func WithValue(parent Context, key, val interface{}) Context {
// delegates all other calls to the embedded Context.
type valueCtx struct {
Context
key, val interface{}
key, val any
}
// stringify tries a bit to stringify v, without using fmt, since we don't
// want context depending on the unicode tables. This is only used by
// *valueCtx.String().
func stringify(v interface{}) string {
func stringify(v any) string {
switch s := v.(type) {
case stringer:
return s.String()
@ -559,14 +559,14 @@ func (c *valueCtx) String() string {
", val " + stringify(c.val) + ")"
}
func (c *valueCtx) Value(key interface{}) interface{} {
func (c *valueCtx) Value(key any) any {
if c.key == key {
return c.val
}
return value(c.Context, key)
}
func value(c Context, key interface{}) interface{} {
func value(c Context, key any) any {
for {
switch ctx := c.(type) {
case *valueCtx:

View File

@ -16,21 +16,21 @@ import (
type testingT interface {
Deadline() (time.Time, bool)
Error(args ...interface{})
Errorf(format string, args ...interface{})
Error(args ...any)
Errorf(format string, args ...any)
Fail()
FailNow()
Failed() bool
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
Fatal(args ...any)
Fatalf(format string, args ...any)
Helper()
Log(args ...interface{})
Logf(format string, args ...interface{})
Log(args ...any)
Logf(format string, args ...any)
Name() string
Parallel()
Skip(args ...interface{})
Skip(args ...any)
SkipNow()
Skipf(format string, args ...interface{})
Skipf(format string, args ...any)
Skipped() bool
}
@ -553,7 +553,7 @@ func testLayers(t testingT, seed int64, testTimeout bool) {
t.Parallel()
r := rand.New(rand.NewSource(seed))
errorf := func(format string, a ...interface{}) {
errorf := func(format string, a ...any) {
t.Errorf(fmt.Sprintf("seed=%d: %s", seed, format), a...)
}
const (
@ -691,7 +691,7 @@ func XTestInvalidDerivedFail(t testingT) {
}
}
func recoveredValue(fn func()) (v interface{}) {
func recoveredValue(fn func()) (v any) {
defer func() { v = recover() }()
fn()
return

View File

@ -159,7 +159,7 @@ func RegisterHash(h Hash, f func() hash.Hash) {
// }
//
// which can be used for increased type safety within applications.
type PublicKey interface{}
type PublicKey any
// PrivateKey represents a private key using an unspecified algorithm.
//
@ -173,7 +173,7 @@ type PublicKey interface{}
//
// as well as purpose-specific interfaces such as Signer and Decrypter, which
// can be used for increased type safety within applications.
type PrivateKey interface{}
type PrivateKey any
// Signer is an interface for an opaque private key that can be used for
// signing operations. For example, an RSA key kept in a hardware module.
@ -220,4 +220,4 @@ type Decrypter interface {
Decrypt(rand io.Reader, msg []byte, opts DecrypterOpts) (plaintext []byte, err error)
}
type DecrypterOpts interface{}
type DecrypterOpts any

View File

@ -71,7 +71,7 @@ func TestScalarAliasing(t *testing.T) {
return x == x1 && y == y1
}
for name, f := range map[string]interface{}{
for name, f := range map[string]any{
"Negate": func(v, x Scalar) bool {
return checkAliasingOneArg((*Scalar).Negate, v, x)
},

View File

@ -140,7 +140,7 @@ type cipherSuite struct {
ka func(version uint16) keyAgreement
// flags is a bitmask of the suite* values, above.
flags int
cipher func(key, iv []byte, isRead bool) interface{}
cipher func(key, iv []byte, isRead bool) any
mac func(key []byte) hash.Hash
aead func(key, fixedNonce []byte) aead
}
@ -399,12 +399,12 @@ func aesgcmPreferred(ciphers []uint16) bool {
return false
}
func cipherRC4(key, iv []byte, isRead bool) interface{} {
func cipherRC4(key, iv []byte, isRead bool) any {
cipher, _ := rc4.NewCipher(key)
return cipher
}
func cipher3DES(key, iv []byte, isRead bool) interface{} {
func cipher3DES(key, iv []byte, isRead bool) any {
block, _ := des.NewTripleDESCipher(key)
if isRead {
return cipher.NewCBCDecrypter(block, iv)
@ -412,7 +412,7 @@ func cipher3DES(key, iv []byte, isRead bool) interface{} {
return cipher.NewCBCEncrypter(block, iv)
}
func cipherAES(key, iv []byte, isRead bool) interface{} {
func cipherAES(key, iv []byte, isRead bool) any {
block, _ := aes.NewCipher(key)
if isRead {
return cipher.NewCBCDecrypter(block, iv)

View File

@ -1466,7 +1466,7 @@ func defaultConfig() *Config {
return &emptyConfig
}
func unexpectedMessageError(wanted, got interface{}) error {
func unexpectedMessageError(wanted, got any) error {
return fmt.Errorf("tls: received unexpected handshake message of type %T when waiting for %T", got, wanted)
}

View File

@ -163,16 +163,16 @@ func (c *Conn) NetConn() net.Conn {
type halfConn struct {
sync.Mutex
err error // first permanent error
version uint16 // protocol version
cipher interface{} // cipher algorithm
err error // first permanent error
version uint16 // protocol version
cipher any // cipher algorithm
mac hash.Hash
seq [8]byte // 64-bit sequence number
scratchBuf [13]byte // to avoid allocs; interface method args escape
nextCipher interface{} // next encryption state
nextMac hash.Hash // next MAC algorithm
nextCipher any // next encryption state
nextMac hash.Hash // next MAC algorithm
trafficSecret []byte // current TLS 1.3 traffic secret
}
@ -197,7 +197,7 @@ func (hc *halfConn) setErrorLocked(err error) error {
// prepareCipherSpec sets the encryption and MAC states
// that a subsequent changeCipherSpec will use.
func (hc *halfConn) prepareCipherSpec(version uint16, cipher interface{}, mac hash.Hash) {
func (hc *halfConn) prepareCipherSpec(version uint16, cipher any, mac hash.Hash) {
hc.version = version
hc.nextCipher = cipher
hc.nextMac = mac
@ -935,7 +935,7 @@ func (c *Conn) flush() (int, error) {
// outBufPool pools the record-sized scratch buffers used by writeRecordLocked.
var outBufPool = sync.Pool{
New: func() interface{} {
New: func() any {
return new([]byte)
},
}
@ -1011,7 +1011,7 @@ func (c *Conn) writeRecord(typ recordType, data []byte) (int, error) {
// readHandshake reads the next handshake message from
// the record layer.
func (c *Conn) readHandshake() (interface{}, error) {
func (c *Conn) readHandshake() (any, error) {
for c.hand.Len() < 4 {
if err := c.readRecord(); err != nil {
return nil, err

View File

@ -37,7 +37,7 @@ var (
ed25519Key = flag.Bool("ed25519", false, "Generate an Ed25519 key")
)
func publicKey(priv interface{}) interface{} {
func publicKey(priv any) any {
switch k := priv.(type) {
case *rsa.PrivateKey:
return &k.PublicKey
@ -57,7 +57,7 @@ func main() {
log.Fatalf("Missing required --host parameter")
}
var priv interface{}
var priv any
var err error
switch *ecdsaCurve {
case "":

View File

@ -657,7 +657,7 @@ func (hs *clientHandshakeState) establishKeys() error {
clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV :=
keysFromMasterSecret(c.vers, hs.suite, hs.masterSecret, hs.hello.random, hs.serverHello.random, hs.suite.macLen, hs.suite.keyLen, hs.suite.ivLen)
var clientCipher, serverCipher interface{}
var clientCipher, serverCipher any
var clientHash, serverHash hash.Hash
if hs.suite.cipher != nil {
clientCipher = hs.suite.cipher(clientKey, clientIV, false /* not for reading */)

View File

@ -134,7 +134,7 @@ type clientTest struct {
cert []byte
// key, if not nil, contains either a *rsa.PrivateKey, ed25519.PrivateKey or
// *ecdsa.PrivateKey which is the private key for the reference server.
key interface{}
key any
// extensions, if not nil, contains a list of extension data to be returned
// from the ServerHello. The data should be in standard TLS format with
// a 2-byte uint16 type, 2-byte data length, followed by the extension data.
@ -171,7 +171,7 @@ func (test *clientTest) connFromCommand() (conn *recordingConn, child *exec.Cmd,
certPath := tempFile(string(cert))
defer os.Remove(certPath)
var key interface{} = testRSAPrivateKey
var key any = testRSAPrivateKey
if test.key != nil {
key = test.key
}

View File

@ -14,7 +14,7 @@ import (
"time"
)
var tests = []interface{}{
var tests = []any{
&clientHelloMsg{},
&serverHelloMsg{},
&finishedMsg{},

View File

@ -681,7 +681,7 @@ func (hs *serverHandshakeState) establishKeys() error {
clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV :=
keysFromMasterSecret(c.vers, hs.suite, hs.masterSecret, hs.clientHello.random, hs.hello.random, hs.suite.macLen, hs.suite.keyLen, hs.suite.ivLen)
var clientCipher, serverCipher interface{}
var clientCipher, serverCipher any
var clientHash, serverHash hash.Hash
if hs.suite.aead == nil {

View File

@ -249,7 +249,7 @@ func TestTLS12OnlyCipherSuites(t *testing.T) {
}
c, s := localPipe(t)
replyChan := make(chan interface{})
replyChan := make(chan any)
go func() {
cli := Client(c, testConfig)
cli.vers = clientHello.vers
@ -304,7 +304,7 @@ func TestTLSPointFormats(t *testing.T) {
}
c, s := localPipe(t)
replyChan := make(chan interface{})
replyChan := make(chan any)
go func() {
cli := Client(c, testConfig)
cli.vers = clientHello.vers
@ -600,7 +600,7 @@ func (test *serverTest) connFromCommand() (conn *recordingConn, child *exec.Cmd,
return nil, nil, err
}
connChan := make(chan interface{}, 1)
connChan := make(chan any, 1)
go func() {
tcpConn, err := l.Accept()
if err != nil {

Some files were not shown because too many files have changed in this diff Show More