]> Cypherpunks repositories - gostls13.git/commitdiff
std: add //go:fix inline directives to some deprecated functions
authorAlan Donovan <adonovan@google.com>
Wed, 12 Feb 2025 16:18:30 +0000 (11:18 -0500)
committerGopher Robot <gobot@golang.org>
Sat, 15 Feb 2025 16:06:58 +0000 (08:06 -0800)
In particular, we apply it only to functions where it is always
a code improvement to inline the call.
We also apply it to some constants.

In a few cases this may introduce a panic statement at the
caller, which is debatable, but making the potential for panic
evident is the purpose of the deprecation.

The gofix analyzer in gopls v0.18 will show a diagnostic for calls
to the annotated functions, and will offer to inline the call.

The new //go:fix annotation needs a special exemption in the
pragma check in the compiler.

Updates #32816

Change-Id: I43bf15648ac12251734109eb7102394f8a76d55e
Reviewed-on: https://go-review.googlesource.com/c/go/+/648995
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/noder/noder.go
src/go/importer/importer.go
src/go/types/signature.go
src/io/ioutil/ioutil.go
src/io/ioutil/tempfile.go
src/reflect/type.go

index 7905c374c5e971a36e906b3db68f68a9176e314d..77daf9eda59085239afa546ce4607c5ec3c4e451 100644 (file)
@@ -162,6 +162,7 @@ var allowedStdPragmas = map[string]bool{
        "go:cgo_ldflag":         true,
        "go:cgo_dynamic_linker": true,
        "go:embed":              true,
+       "go:fix":                true,
        "go:generate":           true,
 }
 
index 54acd7e694020244a22e4809f0c151a2dbdeaa57..f0a1f651d2636caf408f4a1610a6458e1e14b9e1 100644 (file)
@@ -80,6 +80,8 @@ func ForCompiler(fset *token.FileSet, compiler string, lookup Lookup) types.Impo
 //
 // Deprecated: Use [ForCompiler], which populates a FileSet
 // with the positions of objects created by the importer.
+//
+//go:fix inline
 func For(compiler string, lookup Lookup) types.Importer {
        return ForCompiler(token.NewFileSet(), compiler, lookup)
 }
index 1738384febcc0007f0d454878d7921b73d367a07..365b1119393dd25aa734708af44189147ffd8d04 100644 (file)
@@ -38,6 +38,8 @@ type Signature struct {
 // must be of unnamed slice type.
 //
 // Deprecated: Use [NewSignatureType] instead which allows for type parameters.
+//
+//go:fix inline
 func NewSignature(recv *Var, params, results *Tuple, variadic bool) *Signature {
        return NewSignatureType(recv, nil, nil, params, results, variadic)
 }
index af8ebe38501d4c8153caff15574bdeba78ccf079..0ab4b5a0c333d979607c1f65d554e1659ac03dc5 100644 (file)
@@ -24,6 +24,8 @@ import (
 // as an error to be reported.
 //
 // Deprecated: As of Go 1.16, this function simply calls [io.ReadAll].
+//
+//go:fix inline
 func ReadAll(r io.Reader) ([]byte, error) {
        return io.ReadAll(r)
 }
@@ -34,6 +36,8 @@ func ReadAll(r io.Reader) ([]byte, error) {
 // to be reported.
 //
 // Deprecated: As of Go 1.16, this function simply calls [os.ReadFile].
+//
+//go:fix inline
 func ReadFile(filename string) ([]byte, error) {
        return os.ReadFile(filename)
 }
@@ -43,6 +47,8 @@ func ReadFile(filename string) ([]byte, error) {
 // (before umask); otherwise WriteFile truncates it before writing, without changing permissions.
 //
 // Deprecated: As of Go 1.16, this function simply calls [os.WriteFile].
+//
+//go:fix inline
 func WriteFile(filename string, data []byte, perm fs.FileMode) error {
        return os.WriteFile(filename, data, perm)
 }
@@ -87,6 +93,8 @@ func ReadDir(dirname string) ([]fs.FileInfo, error) {
 // the provided Reader r.
 //
 // Deprecated: As of Go 1.16, this function simply calls [io.NopCloser].
+//
+//go:fix inline
 func NopCloser(r io.Reader) io.ReadCloser {
        return io.NopCloser(r)
 }
index 47b2e4012f7622334111b7df0a40e910945a6907..ef2ce404d9ae8f6d902dae0b1c3917cafe47c925 100644 (file)
@@ -21,6 +21,8 @@ import (
 // to remove the file when no longer needed.
 //
 // Deprecated: As of Go 1.17, this function simply calls [os.CreateTemp].
+//
+//go:fix inline
 func TempFile(dir, pattern string) (f *os.File, err error) {
        return os.CreateTemp(dir, pattern)
 }
@@ -36,6 +38,8 @@ func TempFile(dir, pattern string) (f *os.File, err error) {
 // to remove the directory when no longer needed.
 //
 // Deprecated: As of Go 1.17, this function simply calls [os.MkdirTemp].
+//
+//go:fix inline
 func TempDir(dir, pattern string) (name string, err error) {
        return os.MkdirTemp(dir, pattern)
 }
index e5ee7f90d0202c11ab14de1d90dea72ffd83e1cc..b6fc99a9347cd450806ab3e45c55ecccd156a5e2 100644 (file)
@@ -301,6 +301,8 @@ const (
 )
 
 // Ptr is the old name for the [Pointer] kind.
+//
+//go:fix inline
 const Ptr = Pointer
 
 // uncommonType is present only for defined types or types with methods
@@ -1323,6 +1325,8 @@ var ptrMap sync.Map // map[*rtype]*ptrType
 // The two functions behave identically.
 //
 // Deprecated: Superseded by [PointerTo].
+//
+//go:fix inline
 func PtrTo(t Type) Type { return PointerTo(t) }
 
 // PointerTo returns the pointer type with element t.