deprecated.go (15660B)
1 package knowledge 2 3 const ( 4 // DeprecatedNeverUse indicates that an API should never be used, regardless of Go version. 5 DeprecatedNeverUse = "never" 6 // DeprecatedUseNoLonger indicates that an API has no use anymore. 7 DeprecatedUseNoLonger = "no longer" 8 ) 9 10 // Deprecation describes when a Go API has been deprecated. 11 type Deprecation struct { 12 // The minor Go version since which this API has been deprecated. 13 DeprecatedSince string 14 // The minor Go version since which an alternative API has been available. 15 // May also be one of DeprecatedNeverUse or DeprecatedUseNoLonger. 16 AlternativeAvailableSince string 17 } 18 19 // go/importer.ForCompiler contains "Deprecated:", but it refers to a single argument, not the whole function. 20 // Luckily, the notice starts in the middle of a paragraph, and as such isn't detected by us. 21 22 // TODO(dh): StdlibDeprecations doesn't contain entries for internal packages and unexported API. That's fine for normal 23 // users, but makes the Deprecated check less useful for people working on Go itself. 24 25 // StdlibDeprecations contains a mapping of Go API (such as variables, methods, or fields, among others) 26 // to information about when it has been deprecated. 27 var StdlibDeprecations = map[string]Deprecation{ 28 // FIXME(dh): AllowBinary isn't being detected as deprecated 29 // because the comment has a newline right after "Deprecated:" 30 "go/build.AllowBinary": {"go1.7", "go1.7"}, 31 "(archive/zip.FileHeader).CompressedSize": {"go1.1", "go1.1"}, 32 "(archive/zip.FileHeader).UncompressedSize": {"go1.1", "go1.1"}, 33 "(archive/zip.FileHeader).ModifiedTime": {"go1.10", "go1.10"}, 34 "(archive/zip.FileHeader).ModifiedDate": {"go1.10", "go1.10"}, 35 "(*archive/zip.FileHeader).ModTime": {"go1.10", "go1.10"}, 36 "(*archive/zip.FileHeader).SetModTime": {"go1.10", "go1.10"}, 37 "(go/doc.Package).Bugs": {"go1.1", "go1.1"}, 38 "os.SEEK_SET": {"go1.7", "go1.7"}, 39 "os.SEEK_CUR": {"go1.7", "go1.7"}, 40 "os.SEEK_END": {"go1.7", "go1.7"}, 41 "(net.Dialer).Cancel": {"go1.7", "go1.7"}, 42 "runtime.CPUProfile": {"go1.9", "go1.0"}, 43 "compress/flate.ReadError": {"go1.6", DeprecatedUseNoLonger}, 44 "compress/flate.WriteError": {"go1.6", DeprecatedUseNoLonger}, 45 "path/filepath.HasPrefix": {"go1.0", DeprecatedNeverUse}, 46 "(net/http.Transport).Dial": {"go1.7", "go1.7"}, 47 "(net/http.Transport).DialTLS": {"go1.14", "go1.14"}, 48 "(*net/http.Transport).CancelRequest": {"go1.6", "go1.5"}, 49 "net/http.ErrWriteAfterFlush": {"go1.7", DeprecatedUseNoLonger}, 50 "net/http.ErrHeaderTooLong": {"go1.8", DeprecatedUseNoLonger}, 51 "net/http.ErrShortBody": {"go1.8", DeprecatedUseNoLonger}, 52 "net/http.ErrMissingContentLength": {"go1.8", DeprecatedUseNoLonger}, 53 "net/http/httputil.ErrPersistEOF": {"go1.0", DeprecatedUseNoLonger}, 54 "net/http/httputil.ErrClosed": {"go1.0", DeprecatedUseNoLonger}, 55 "net/http/httputil.ErrPipeline": {"go1.0", DeprecatedUseNoLonger}, 56 "net/http/httputil.ServerConn": {"go1.0", "go1.0"}, 57 "net/http/httputil.NewServerConn": {"go1.0", "go1.0"}, 58 "net/http/httputil.ClientConn": {"go1.0", "go1.0"}, 59 "net/http/httputil.NewClientConn": {"go1.0", "go1.0"}, 60 "net/http/httputil.NewProxyClientConn": {"go1.0", "go1.0"}, 61 "(net/http.Request).Cancel": {"go1.7", "go1.7"}, 62 "(text/template/parse.PipeNode).Line": {"go1.1", DeprecatedUseNoLonger}, 63 "(text/template/parse.ActionNode).Line": {"go1.1", DeprecatedUseNoLonger}, 64 "(text/template/parse.BranchNode).Line": {"go1.1", DeprecatedUseNoLonger}, 65 "(text/template/parse.TemplateNode).Line": {"go1.1", DeprecatedUseNoLonger}, 66 "database/sql/driver.ColumnConverter": {"go1.9", "go1.9"}, 67 "database/sql/driver.Execer": {"go1.8", "go1.8"}, 68 "database/sql/driver.Queryer": {"go1.8", "go1.8"}, 69 "(database/sql/driver.Conn).Begin": {"go1.8", "go1.8"}, 70 "(database/sql/driver.Stmt).Exec": {"go1.8", "go1.8"}, 71 "(database/sql/driver.Stmt).Query": {"go1.8", "go1.8"}, 72 "syscall.StringByteSlice": {"go1.1", "go1.1"}, 73 "syscall.StringBytePtr": {"go1.1", "go1.1"}, 74 "syscall.StringSlicePtr": {"go1.1", "go1.1"}, 75 "syscall.StringToUTF16": {"go1.1", "go1.1"}, 76 "syscall.StringToUTF16Ptr": {"go1.1", "go1.1"}, 77 "(*regexp.Regexp).Copy": {"go1.12", DeprecatedUseNoLonger}, 78 "(archive/tar.Header).Xattrs": {"go1.10", "go1.10"}, 79 "archive/tar.TypeRegA": {"go1.11", "go1.1"}, 80 "go/types.NewInterface": {"go1.11", "go1.11"}, 81 "(*go/types.Interface).Embedded": {"go1.11", "go1.11"}, 82 "go/importer.For": {"go1.12", "go1.12"}, 83 "encoding/json.InvalidUTF8Error": {"go1.2", DeprecatedUseNoLonger}, 84 "encoding/json.UnmarshalFieldError": {"go1.2", DeprecatedUseNoLonger}, 85 "encoding/csv.ErrTrailingComma": {"go1.2", DeprecatedUseNoLonger}, 86 "(encoding/csv.Reader).TrailingComma": {"go1.2", DeprecatedUseNoLonger}, 87 "(net.Dialer).DualStack": {"go1.12", "go1.12"}, 88 "net/http.ErrUnexpectedTrailer": {"go1.12", DeprecatedUseNoLonger}, 89 "net/http.CloseNotifier": {"go1.11", "go1.7"}, 90 // This is hairy. The notice says "Not all errors in the http package related to protocol errors are of type ProtocolError", but doesn't that imply that some errors do? 91 "net/http.ProtocolError": {"go1.8", DeprecatedUseNoLonger}, 92 "(crypto/x509.CertificateRequest).Attributes": {"go1.5", "go1.3"}, 93 "(*crypto/x509.Certificate).CheckCRLSignature": {"go1.19", "go1.19"}, 94 "crypto/x509.ParseCRL": {"go1.19", "go1.19"}, 95 "crypto/x509.ParseDERCRL": {"go1.19", "go1.19"}, 96 "(*crypto/x509.Certificate).CreateCRL": {"go1.19", "go1.19"}, 97 "crypto/x509/pkix.TBSCertificateList": {"go1.19", "go1.19"}, 98 "crypto/x509/pkix.RevokedCertificate": {"go1.19", "go1.19"}, 99 "go/doc.ToHTML": {"go1.20", "go1.20"}, 100 "go/doc.ToText": {"go1.20", "go1.20"}, 101 "go/doc.Synopsis": {"go1.20", "go1.20"}, 102 "math/rand.Seed": {"go1.20", "go1.0"}, 103 "math/rand.Read": {"go1.20", DeprecatedNeverUse}, 104 105 // These functions have no direct alternative, but they are insecure and should no longer be used. 106 "crypto/x509.IsEncryptedPEMBlock": {"go1.16", DeprecatedNeverUse}, 107 "crypto/x509.DecryptPEMBlock": {"go1.16", DeprecatedNeverUse}, 108 "crypto/x509.EncryptPEMBlock": {"go1.16", DeprecatedNeverUse}, 109 "crypto/dsa": {"go1.16", DeprecatedNeverUse}, 110 111 // This function has no alternative, but also no purpose. 112 "(*crypto/rc4.Cipher).Reset": {"go1.12", DeprecatedNeverUse}, 113 "(net/http/httptest.ResponseRecorder).HeaderMap": {"go1.11", "go1.7"}, 114 "image.ZP": {"go1.13", "go1.0"}, 115 "image.ZR": {"go1.13", "go1.0"}, 116 "(*debug/gosym.LineTable).LineToPC": {"go1.2", "go1.2"}, 117 "(*debug/gosym.LineTable).PCToLine": {"go1.2", "go1.2"}, 118 "crypto/tls.VersionSSL30": {"go1.13", DeprecatedNeverUse}, 119 "(crypto/tls.Config).NameToCertificate": {"go1.14", DeprecatedUseNoLonger}, 120 "(*crypto/tls.Config).BuildNameToCertificate": {"go1.14", DeprecatedUseNoLonger}, 121 "(crypto/tls.Config).SessionTicketKey": {"go1.16", "go1.5"}, 122 // No alternative, no use 123 "(crypto/tls.ConnectionState).NegotiatedProtocolIsMutual": {"go1.16", DeprecatedNeverUse}, 124 // No alternative, but insecure 125 "(crypto/tls.ConnectionState).TLSUnique": {"go1.16", DeprecatedNeverUse}, 126 "image/jpeg.Reader": {"go1.4", DeprecatedNeverUse}, 127 128 // All of these have been deprecated in favour of external libraries 129 "syscall.AttachLsf": {"go1.7", "go1.0"}, 130 "syscall.DetachLsf": {"go1.7", "go1.0"}, 131 "syscall.LsfSocket": {"go1.7", "go1.0"}, 132 "syscall.SetLsfPromisc": {"go1.7", "go1.0"}, 133 "syscall.LsfJump": {"go1.7", "go1.0"}, 134 "syscall.LsfStmt": {"go1.7", "go1.0"}, 135 "syscall.BpfStmt": {"go1.7", "go1.0"}, 136 "syscall.BpfJump": {"go1.7", "go1.0"}, 137 "syscall.BpfBuflen": {"go1.7", "go1.0"}, 138 "syscall.SetBpfBuflen": {"go1.7", "go1.0"}, 139 "syscall.BpfDatalink": {"go1.7", "go1.0"}, 140 "syscall.SetBpfDatalink": {"go1.7", "go1.0"}, 141 "syscall.SetBpfPromisc": {"go1.7", "go1.0"}, 142 "syscall.FlushBpf": {"go1.7", "go1.0"}, 143 "syscall.BpfInterface": {"go1.7", "go1.0"}, 144 "syscall.SetBpfInterface": {"go1.7", "go1.0"}, 145 "syscall.BpfTimeout": {"go1.7", "go1.0"}, 146 "syscall.SetBpfTimeout": {"go1.7", "go1.0"}, 147 "syscall.BpfStats": {"go1.7", "go1.0"}, 148 "syscall.SetBpfImmediate": {"go1.7", "go1.0"}, 149 "syscall.SetBpf": {"go1.7", "go1.0"}, 150 "syscall.CheckBpfVersion": {"go1.7", "go1.0"}, 151 "syscall.BpfHeadercmpl": {"go1.7", "go1.0"}, 152 "syscall.SetBpfHeadercmpl": {"go1.7", "go1.0"}, 153 "syscall.RouteRIB": {"go1.8", "go1.0"}, 154 "syscall.RoutingMessage": {"go1.8", "go1.0"}, 155 "syscall.RouteMessage": {"go1.8", "go1.0"}, 156 "syscall.InterfaceMessage": {"go1.8", "go1.0"}, 157 "syscall.InterfaceAddrMessage": {"go1.8", "go1.0"}, 158 "syscall.ParseRoutingMessage": {"go1.8", "go1.0"}, 159 "syscall.ParseRoutingSockaddr": {"go1.8", "go1.0"}, 160 "syscall.InterfaceAnnounceMessage": {"go1.7", "go1.0"}, 161 "syscall.InterfaceMulticastAddrMessage": {"go1.7", "go1.0"}, 162 "syscall.FormatMessage": {"go1.5", "go1.0"}, 163 "syscall.PostQueuedCompletionStatus": {"go1.17", "go1.0"}, 164 "syscall.GetQueuedCompletionStatus": {"go1.17", "go1.0"}, 165 "syscall.CreateIoCompletionPort": {"go1.17", "go1.0"}, 166 167 // We choose to only track the package itself, even though all functions are deprecated individually, too. Anyone 168 // using ioutil directly will have to import it, and this keeps the noise down. 169 "io/ioutil": {"go1.19", "go1.19"}, 170 171 "bytes.Title": {"go1.18", "go1.0"}, 172 "strings.Title": {"go1.18", "go1.0"}, 173 "(crypto/tls.Config).PreferServerCipherSuites": {"go1.18", DeprecatedUseNoLonger}, 174 // It's not clear if Subjects was okay to use in the past, so we err on the less noisy side of assuming that it was. 175 "(*crypto/x509.CertPool).Subjects": {"go1.18", DeprecatedUseNoLonger}, 176 "go/types.NewSignature": {"go1.18", "go1.18"}, 177 "(net.Error).Temporary": {"go1.18", DeprecatedNeverUse}, 178 // InterfaceData is another tricky case. It was deprecated in Go 1.18, but has been useless since Go 1.4, and an 179 // "alternative" (using your own unsafe hacks) has existed forever. We don't want to get into hairsplitting with 180 // users who somehow successfully used this between 1.4 and 1.18, so we'll just tag it as deprecated since 1.18. 181 "(reflect.Value).InterfaceData": {"go1.18", "go1.18"}, 182 183 // The following objects are only deprecated on Windows. 184 "syscall.Syscall": {"go1.18", "go1.18"}, 185 "syscall.Syscall12": {"go1.18", "go1.18"}, 186 "syscall.Syscall15": {"go1.18", "go1.18"}, 187 "syscall.Syscall18": {"go1.18", "go1.18"}, 188 "syscall.Syscall6": {"go1.18", "go1.18"}, 189 "syscall.Syscall9": {"go1.18", "go1.18"}, 190 191 "reflect.SliceHeader": {"go1.21", "go1.17"}, 192 "reflect.StringHeader": {"go1.21", "go1.20"}, 193 "crypto/elliptic.GenerateKey": {"go1.21", "go1.21"}, 194 "crypto/elliptic.Marshal": {"go1.21", "go1.21"}, 195 "crypto/elliptic.Unmarshal": {"go1.21", "go1.21"}, 196 "(*crypto/elliptic.CurveParams).Add": {"go1.21", "go1.21"}, 197 "(*crypto/elliptic.CurveParams).Double": {"go1.21", "go1.21"}, 198 "(*crypto/elliptic.CurveParams).IsOnCurve": {"go1.21", "go1.21"}, 199 "(*crypto/elliptic.CurveParams).ScalarBaseMult": {"go1.21", "go1.21"}, 200 "(*crypto/elliptic.CurveParams).ScalarMult": {"go1.21", "go1.21"}, 201 "(crypto/elliptic.Curve).Add": {"go1.21", "go1.21"}, 202 "(crypto/elliptic.Curve).Double": {"go1.21", "go1.21"}, 203 "(crypto/elliptic.Curve).IsOnCurve": {"go1.21", "go1.21"}, 204 "(crypto/elliptic.Curve).ScalarBaseMult": {"go1.21", "go1.21"}, 205 "(crypto/elliptic.Curve).ScalarMult": {"go1.21", "go1.21"}, 206 207 "crypto/rsa.GenerateMultiPrimeKey": {"go1.21", DeprecatedNeverUse}, 208 "(crypto/rsa.PrecomputedValues).CRTValues": {"go1.21", DeprecatedNeverUse}, 209 "(crypto/x509.RevocationList).RevokedCertificates": {"go1.21", "go1.21"}, 210 211 "go/ast.NewPackage": {"go1.22", "go1.0"}, 212 "go/ast.Importer": {"go1.22", "go1.0"}, 213 "go/ast.Object": {"go1.22", "go1.0"}, 214 "go/ast.Package": {"go1.22", "go1.0"}, 215 "go/ast.Scope": {"go1.22", "go1.0"}, 216 "html/template.ErrJSTemplate": {"go1.22", DeprecatedUseNoLonger}, 217 "reflect.PtrTo": {"go1.22", "go1.18"}, 218 219 // Technically, runtime.GOROOT could be considered DeprecatedNeverUse, but 220 // using it used to be a lot more common and accepted. 221 "runtime.GOROOT": {"go1.24", DeprecatedUseNoLonger}, 222 // These are never safe to use; a concrete alternative was added in Go 1.2 (crypto/cipher.AEAD). 223 "crypto/cipher.NewCFBDecrypter": {"go1.24", "go1.2"}, 224 "crypto/cipher.NewCFBEncrypter": {"go1.24", "go1.2"}, 225 "crypto/cipher.NewOFB": {"go1.24", "go1.2"}, 226 227 "go/ast.FilterFuncDuplicates": {"go1.25", "go1.0"}, 228 "go/ast.FilterImportDuplicates": {"go1.25", "go1.0"}, 229 "go/ast.FilterUnassociatedComments": {"go1.25", "go1.0"}, 230 "go/ast.FilterPackage": {"go1.25", "go1.0"}, 231 "go/ast.MergePackageFiles": {"go1.25", "go1.0"}, 232 "go/ast.PackageExports": {"go1.25", "go1.0"}, 233 "go/ast.MergeMode": {"go1.25", "go1.0"}, 234 // Go 1.11 because that's around the time x/tools/go/packages was released. 235 "go/parser.ParseDir": {"go1.25", "go1.11"}, 236 237 // Go 1.25 is the first version to provide all of the alternatives mentioned 238 // by the deprecation note. 239 "(crypto/ecdsa.PublicKey).X": {"go1.26", "go1.25"}, 240 "(crypto/ecdsa.PublicKey).Y": {"go1.26", "go1.25"}, 241 "(crypto/ecdsa.PrivateKey).D": {"go1.26", "go1.25"}, 242 243 "crypto/rsa.DecryptPKCS1v15": {"go1.26", DeprecatedNeverUse}, 244 "crypto/rsa.DecryptPKCS1v15SessionKey": {"go1.26", DeprecatedNeverUse}, 245 "crypto/rsa.PKCS1v15DecryptOptions": {"go1.26", DeprecatedNeverUse}, 246 "crypto/rsa.EncryptPKCS1v15": {"go1.26", DeprecatedNeverUse}, 247 248 "(net/http/httputil.ReverseProxy).Director": {"go1.26", "go1.20"}, 249 250 // Note that the available alternative, testing/cryptotest.SetGlobalRandom 251 // is only an alternative for testing, not all possible uses of the 252 // deprecated field. 253 "(crypto/tls.Config).Rand": {"go1.27", "go1.26"}, 254 } 255 256 // Last imported from GOROOT/api/go1.26.txt at d3ddc4854429185e6e06ca1f7628bb790404abb5.