deprecated.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. package knowledge
  2. const (
  3. // DeprecatedNeverUse indicates that an API should never be used, regardless of Go version.
  4. DeprecatedNeverUse = -1
  5. // DeprecatedUseNoLonger indicates that an API has no use anymore.
  6. DeprecatedUseNoLonger = -2
  7. )
  8. // Deprecation describes when a Go API has been deprecated.
  9. type Deprecation struct {
  10. // The minor Go version since which this API has been deprecated.
  11. DeprecatedSince int
  12. // The minor Go version since which an alternative API has been available.
  13. // May also be one of DeprecatedNeverUse or DeprecatedUseNoLonger.
  14. AlternativeAvailableSince int
  15. }
  16. // go/importer.ForCompiler contains "Deprecated:", but it refers to a single argument, not the whole function.
  17. // Luckily, the notice starts in the middle of a paragraph, and as such isn't detected by us.
  18. // StdlibDeprecations contains a mapping of Go API (such as variables, methods, or fields, among others)
  19. // to information about when it has been deprecated.
  20. var StdlibDeprecations = map[string]Deprecation{
  21. // FIXME(dh): AllowBinary isn't being detected as deprecated
  22. // because the comment has a newline right after "Deprecated:"
  23. "go/build.AllowBinary": {7, 7},
  24. "(archive/zip.FileHeader).CompressedSize": {1, 1},
  25. "(archive/zip.FileHeader).UncompressedSize": {1, 1},
  26. "(archive/zip.FileHeader).ModifiedTime": {10, 10},
  27. "(archive/zip.FileHeader).ModifiedDate": {10, 10},
  28. "(*archive/zip.FileHeader).ModTime": {10, 10},
  29. "(*archive/zip.FileHeader).SetModTime": {10, 10},
  30. "(go/doc.Package).Bugs": {1, 1},
  31. "os.SEEK_SET": {7, 7},
  32. "os.SEEK_CUR": {7, 7},
  33. "os.SEEK_END": {7, 7},
  34. "(net.Dialer).Cancel": {7, 7},
  35. "runtime.CPUProfile": {9, 0},
  36. "compress/flate.ReadError": {6, DeprecatedUseNoLonger},
  37. "compress/flate.WriteError": {6, DeprecatedUseNoLonger},
  38. "path/filepath.HasPrefix": {0, DeprecatedNeverUse},
  39. "(net/http.Transport).Dial": {7, 7},
  40. "(net/http.Transport).DialTLS": {14, 14},
  41. "(*net/http.Transport).CancelRequest": {6, 5},
  42. "net/http.ErrWriteAfterFlush": {7, DeprecatedUseNoLonger},
  43. "net/http.ErrHeaderTooLong": {8, DeprecatedUseNoLonger},
  44. "net/http.ErrShortBody": {8, DeprecatedUseNoLonger},
  45. "net/http.ErrMissingContentLength": {8, DeprecatedUseNoLonger},
  46. "net/http/httputil.ErrPersistEOF": {0, DeprecatedUseNoLonger},
  47. "net/http/httputil.ErrClosed": {0, DeprecatedUseNoLonger},
  48. "net/http/httputil.ErrPipeline": {0, DeprecatedUseNoLonger},
  49. "net/http/httputil.ServerConn": {0, 0},
  50. "net/http/httputil.NewServerConn": {0, 0},
  51. "net/http/httputil.ClientConn": {0, 0},
  52. "net/http/httputil.NewClientConn": {0, 0},
  53. "net/http/httputil.NewProxyClientConn": {0, 0},
  54. "(net/http.Request).Cancel": {7, 7},
  55. "(text/template/parse.PipeNode).Line": {1, DeprecatedUseNoLonger},
  56. "(text/template/parse.ActionNode).Line": {1, DeprecatedUseNoLonger},
  57. "(text/template/parse.BranchNode).Line": {1, DeprecatedUseNoLonger},
  58. "(text/template/parse.TemplateNode).Line": {1, DeprecatedUseNoLonger},
  59. "database/sql/driver.ColumnConverter": {9, 9},
  60. "database/sql/driver.Execer": {8, 8},
  61. "database/sql/driver.Queryer": {8, 8},
  62. "(database/sql/driver.Conn).Begin": {8, 8},
  63. "(database/sql/driver.Stmt).Exec": {8, 8},
  64. "(database/sql/driver.Stmt).Query": {8, 8},
  65. "syscall.StringByteSlice": {1, 1},
  66. "syscall.StringBytePtr": {1, 1},
  67. "syscall.StringSlicePtr": {1, 1},
  68. "syscall.StringToUTF16": {1, 1},
  69. "syscall.StringToUTF16Ptr": {1, 1},
  70. "(*regexp.Regexp).Copy": {12, DeprecatedUseNoLonger},
  71. "(archive/tar.Header).Xattrs": {10, 10},
  72. "archive/tar.TypeRegA": {11, 1},
  73. "go/types.NewInterface": {11, 11},
  74. "(*go/types.Interface).Embedded": {11, 11},
  75. "go/importer.For": {12, 12},
  76. "encoding/json.InvalidUTF8Error": {2, DeprecatedUseNoLonger},
  77. "encoding/json.UnmarshalFieldError": {2, DeprecatedUseNoLonger},
  78. "encoding/csv.ErrTrailingComma": {2, DeprecatedUseNoLonger},
  79. "(encoding/csv.Reader).TrailingComma": {2, DeprecatedUseNoLonger},
  80. "(net.Dialer).DualStack": {12, 12},
  81. "net/http.ErrUnexpectedTrailer": {12, DeprecatedUseNoLonger},
  82. "net/http.CloseNotifier": {11, 7},
  83. // 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?
  84. "net/http.ProtocolError": {8, DeprecatedUseNoLonger},
  85. "(crypto/x509.CertificateRequest).Attributes": {5, 3},
  86. // These functions have no direct alternative, but they are insecure and should no longer be used.
  87. "crypto/x509.IsEncryptedPEMBlock": {16, DeprecatedNeverUse},
  88. "crypto/x509.DecryptPEMBlock": {16, DeprecatedNeverUse},
  89. "crypto/x509.EncryptPEMBlock": {16, DeprecatedNeverUse},
  90. "crypto/dsa": {16, DeprecatedNeverUse},
  91. // This function has no alternative, but also no purpose.
  92. "(*crypto/rc4.Cipher).Reset": {12, DeprecatedNeverUse},
  93. "(net/http/httptest.ResponseRecorder).HeaderMap": {11, 7},
  94. "image.ZP": {13, 0},
  95. "image.ZR": {13, 0},
  96. "(*debug/gosym.LineTable).LineToPC": {2, 2},
  97. "(*debug/gosym.LineTable).PCToLine": {2, 2},
  98. "crypto/tls.VersionSSL30": {13, DeprecatedNeverUse},
  99. "(crypto/tls.Config).NameToCertificate": {14, DeprecatedUseNoLonger},
  100. "(*crypto/tls.Config).BuildNameToCertificate": {14, DeprecatedUseNoLonger},
  101. "(crypto/tls.Config).SessionTicketKey": {16, 5},
  102. // No alternative, no use
  103. "(crypto/tls.ConnectionState).NegotiatedProtocolIsMutual": {16, DeprecatedNeverUse},
  104. // No alternative, but insecure
  105. "(crypto/tls.ConnectionState).TLSUnique": {16, DeprecatedNeverUse},
  106. "image/jpeg.Reader": {4, DeprecatedNeverUse},
  107. // All of these have been deprecated in favour of external libraries
  108. "syscall.AttachLsf": {7, 0},
  109. "syscall.DetachLsf": {7, 0},
  110. "syscall.LsfSocket": {7, 0},
  111. "syscall.SetLsfPromisc": {7, 0},
  112. "syscall.LsfJump": {7, 0},
  113. "syscall.LsfStmt": {7, 0},
  114. "syscall.BpfStmt": {7, 0},
  115. "syscall.BpfJump": {7, 0},
  116. "syscall.BpfBuflen": {7, 0},
  117. "syscall.SetBpfBuflen": {7, 0},
  118. "syscall.BpfDatalink": {7, 0},
  119. "syscall.SetBpfDatalink": {7, 0},
  120. "syscall.SetBpfPromisc": {7, 0},
  121. "syscall.FlushBpf": {7, 0},
  122. "syscall.BpfInterface": {7, 0},
  123. "syscall.SetBpfInterface": {7, 0},
  124. "syscall.BpfTimeout": {7, 0},
  125. "syscall.SetBpfTimeout": {7, 0},
  126. "syscall.BpfStats": {7, 0},
  127. "syscall.SetBpfImmediate": {7, 0},
  128. "syscall.SetBpf": {7, 0},
  129. "syscall.CheckBpfVersion": {7, 0},
  130. "syscall.BpfHeadercmpl": {7, 0},
  131. "syscall.SetBpfHeadercmpl": {7, 0},
  132. "syscall.RouteRIB": {8, 0},
  133. "syscall.RoutingMessage": {8, 0},
  134. "syscall.RouteMessage": {8, 0},
  135. "syscall.InterfaceMessage": {8, 0},
  136. "syscall.InterfaceAddrMessage": {8, 0},
  137. "syscall.ParseRoutingMessage": {8, 0},
  138. "syscall.ParseRoutingSockaddr": {8, 0},
  139. "syscall.InterfaceAnnounceMessage": {7, 0},
  140. "syscall.InterfaceMulticastAddrMessage": {7, 0},
  141. "syscall.FormatMessage": {5, 0},
  142. "syscall.PostQueuedCompletionStatus": {17, 0},
  143. "syscall.GetQueuedCompletionStatus": {17, 0},
  144. "syscall.CreateIoCompletionPort": {17, 0},
  145. // Not marked as deprecated with a recognizable header, but deprecated nonetheless.
  146. "io/ioutil": {16, 16},
  147. "bytes.Title": {18, 0},
  148. "strings.Title": {18, 0},
  149. "(crypto/tls.Config).PreferServerCipherSuites": {18, DeprecatedUseNoLonger},
  150. // 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.
  151. "(*crypto/x509.CertPool).Subjects": {18, DeprecatedUseNoLonger},
  152. "go/types.NewSignature": {18, 18},
  153. "(net.Error).Temporary": {18, DeprecatedNeverUse},
  154. // InterfaceData is another tricky case. It was deprecated in Go 1.18, but has been useless since Go 1.4, and an
  155. // "alternative" (using your own unsafe hacks) has existed forever. We don't want to get into hairsplitting with
  156. // users who somehow successfully used this between 1.4 and 1.18, so we'll just tag it as deprecated since 1.18.
  157. "(reflect.Value).InterfaceData": {18, 18},
  158. // The following objects are only deprecated on Windows.
  159. "syscall.Syscall": {18, 18},
  160. "syscall.Syscall12": {18, 18},
  161. "syscall.Syscall15": {18, 18},
  162. "syscall.Syscall18": {18, 18},
  163. "syscall.Syscall6": {18, 18},
  164. "syscall.Syscall9": {18, 18},
  165. }
  166. // Last imported from Go at 4aa1efed4853ea067d665a952eee77c52faac774 with the following numbers of deprecations:
  167. //
  168. // archive/tar/common.go:2
  169. // archive/zip/struct.go:6
  170. // bytes/bytes.go:1
  171. // cmd/compile/internal/ir/expr.go:1
  172. // cmd/compile/internal/ir/type.go:1
  173. // cmd/compile/internal/syntax/walk.go:1
  174. // cmd/compile/internal/types/sym.go:2
  175. // cmd/go/internal/modcmd/edit.go:1
  176. // cmd/go/testdata/mod/example.com_deprecated_a_v1.9.0.txt:2
  177. // cmd/go/testdata/mod/example.com_deprecated_b_v1.9.0.txt:2
  178. // cmd/go/testdata/mod/example.com_undeprecated_v1.0.0.txt:2
  179. // cmd/go/testdata/script/mod_deprecate_message.txt:4
  180. // cmd/go/testdata/script/mod_edit.txt:1
  181. // cmd/go/testdata/script/mod_list_deprecated.txt:2
  182. // cmd/go/testdata/script/mod_list_deprecated_replace.txt:1
  183. // cmd/internal/obj/link.go:5
  184. // cmd/internal/obj/textflag.go:1
  185. // cmd/vendor/golang.org/x/mod/modfile/rule.go:2
  186. // cmd/vendor/golang.org/x/mod/semver/semver.go:1
  187. // cmd/vendor/golang.org/x/sys/unix/zsysnum_darwin_amd64.go:1
  188. // cmd/vendor/golang.org/x/sys/unix/zsysnum_darwin_arm64.go:1
  189. // cmd/vendor/golang.org/x/sys/windows/security_windows.go:1
  190. // cmd/vendor/golang.org/x/sys/windows/syscall_windows.go:2
  191. // compress/flate/inflate.go:2
  192. // crypto/dsa/dsa.go:1
  193. // crypto/rc4/rc4.go:1
  194. // crypto/tls/common.go:7
  195. // crypto/x509/cert_pool.go:1
  196. // crypto/x509/pem_decrypt.go:3
  197. // crypto/x509/x509.go:1
  198. // database/sql/driver/driver.go:6
  199. // debug/gosym/pclntab.go:2
  200. // encoding/csv/reader.go:2
  201. // encoding/json/decode.go:1
  202. // encoding/json/encode.go:1
  203. // go/doc/doc.go:1
  204. // go/importer/importer.go:2
  205. // go/types/errorcodes.go:1
  206. // go/types/interface.go:2
  207. // go/types/signature.go:1
  208. // image/geom.go:2
  209. // image/jpeg/reader.go:1
  210. // net/dial.go:2
  211. // net/http/httptest/recorder.go:1
  212. // net/http/httputil/persist.go:8
  213. // net/http/request.go:6
  214. // net/http/server.go:2
  215. // net/http/socks_bundle.go:1
  216. // net/http/transport.go:3
  217. // net/net.go:1
  218. // os/file.go:1
  219. // path/filepath/path_plan9.go:1
  220. // path/filepath/path_unix.go:1
  221. // path/filepath/path_windows.go:1
  222. // reflect/value.go:1
  223. // regexp/regexp.go:1
  224. // runtime/cpuprof.go:1
  225. // strings/strings.go:1
  226. // syscall/bpf_bsd.go:18
  227. // syscall/bpf_darwin.go:18
  228. // syscall/dll_windows.go:6
  229. // syscall/exec_plan9.go:1
  230. // syscall/exec_unix.go:1
  231. // syscall/lsf_linux.go:6
  232. // syscall/route_bsd.go:7
  233. // syscall/route_darwin.go:1
  234. // syscall/route_dragonfly.go:2
  235. // syscall/route_freebsd.go:2
  236. // syscall/route_netbsd.go:1
  237. // syscall/route_openbsd.go:1
  238. // syscall/syscall.go:3
  239. // syscall/syscall_windows.go:6
  240. // text/template/parse/node.go:5
  241. // vendor/golang.org/x/crypto/curve25519/curve25519.go:1
  242. // vendor/golang.org/x/text/transform/transform.go:1