Skip to content

Commit 586e205

Browse files
adonovangopherbot
authored andcommitted
std: add //go:fix inline directives to some deprecated functions
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 <[email protected]> Commit-Queue: Alan Donovan <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent beac2f7 commit 586e205

File tree

6 files changed

+21
-0
lines changed

6 files changed

+21
-0
lines changed

src/cmd/compile/internal/noder/noder.go

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ var allowedStdPragmas = map[string]bool{
162162
"go:cgo_ldflag": true,
163163
"go:cgo_dynamic_linker": true,
164164
"go:embed": true,
165+
"go:fix": true,
165166
"go:generate": true,
166167
}
167168

src/go/importer/importer.go

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func ForCompiler(fset *token.FileSet, compiler string, lookup Lookup) types.Impo
8080
//
8181
// Deprecated: Use [ForCompiler], which populates a FileSet
8282
// with the positions of objects created by the importer.
83+
//
84+
//go:fix inline
8385
func For(compiler string, lookup Lookup) types.Importer {
8486
return ForCompiler(token.NewFileSet(), compiler, lookup)
8587
}

src/go/types/signature.go

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type Signature struct {
3838
// must be of unnamed slice type.
3939
//
4040
// Deprecated: Use [NewSignatureType] instead which allows for type parameters.
41+
//
42+
//go:fix inline
4143
func NewSignature(recv *Var, params, results *Tuple, variadic bool) *Signature {
4244
return NewSignatureType(recv, nil, nil, params, results, variadic)
4345
}

src/io/ioutil/ioutil.go

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
// as an error to be reported.
2525
//
2626
// Deprecated: As of Go 1.16, this function simply calls [io.ReadAll].
27+
//
28+
//go:fix inline
2729
func ReadAll(r io.Reader) ([]byte, error) {
2830
return io.ReadAll(r)
2931
}
@@ -34,6 +36,8 @@ func ReadAll(r io.Reader) ([]byte, error) {
3436
// to be reported.
3537
//
3638
// Deprecated: As of Go 1.16, this function simply calls [os.ReadFile].
39+
//
40+
//go:fix inline
3741
func ReadFile(filename string) ([]byte, error) {
3842
return os.ReadFile(filename)
3943
}
@@ -43,6 +47,8 @@ func ReadFile(filename string) ([]byte, error) {
4347
// (before umask); otherwise WriteFile truncates it before writing, without changing permissions.
4448
//
4549
// Deprecated: As of Go 1.16, this function simply calls [os.WriteFile].
50+
//
51+
//go:fix inline
4652
func WriteFile(filename string, data []byte, perm fs.FileMode) error {
4753
return os.WriteFile(filename, data, perm)
4854
}
@@ -87,6 +93,8 @@ func ReadDir(dirname string) ([]fs.FileInfo, error) {
8793
// the provided Reader r.
8894
//
8995
// Deprecated: As of Go 1.16, this function simply calls [io.NopCloser].
96+
//
97+
//go:fix inline
9098
func NopCloser(r io.Reader) io.ReadCloser {
9199
return io.NopCloser(r)
92100
}

src/io/ioutil/tempfile.go

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
// to remove the file when no longer needed.
2222
//
2323
// Deprecated: As of Go 1.17, this function simply calls [os.CreateTemp].
24+
//
25+
//go:fix inline
2426
func TempFile(dir, pattern string) (f *os.File, err error) {
2527
return os.CreateTemp(dir, pattern)
2628
}
@@ -36,6 +38,8 @@ func TempFile(dir, pattern string) (f *os.File, err error) {
3638
// to remove the directory when no longer needed.
3739
//
3840
// Deprecated: As of Go 1.17, this function simply calls [os.MkdirTemp].
41+
//
42+
//go:fix inline
3943
func TempDir(dir, pattern string) (name string, err error) {
4044
return os.MkdirTemp(dir, pattern)
4145
}

src/reflect/type.go

+4
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ const (
301301
)
302302

303303
// Ptr is the old name for the [Pointer] kind.
304+
//
305+
//go:fix inline
304306
const Ptr = Pointer
305307

306308
// uncommonType is present only for defined types or types with methods
@@ -1323,6 +1325,8 @@ var ptrMap sync.Map // map[*rtype]*ptrType
13231325
// The two functions behave identically.
13241326
//
13251327
// Deprecated: Superseded by [PointerTo].
1328+
//
1329+
//go:fix inline
13261330
func PtrTo(t Type) Type { return PointerTo(t) }
13271331

13281332
// PointerTo returns the pointer type with element t.

0 commit comments

Comments
 (0)