cmd/api: fix false positive and false negative in isDeprecated

It is made very clear at https://go.dev/wiki/Deprecated and
at https://go.dev/ref/mod#go-mod-file-module-deprecation that a
Deprecated: prefix must be at the start of a paragraph;
it cannot be in the middle of a paragraph, nor can it be in the middle
of a sentence (as demonstrated above). Update isDeprecated accordingly.

This involves updating a frozen api/go1.16.txt file to correct the fact
that go/importer.ForCompiler was accidentally listed as deprecated. The
API of Go 1.16 itself isn't changing, this is merely a consequence of
the cmd/api checker in Go 1.27 starting to report a more accurate actual
API after receiving this bug fix. Fortunately there was nothing else in
the standard library affected by this.

For #79139.
Fixes #79145.

Change-Id: I456b88e3253cacb230aa7c3c5ab4972c80c356e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/774881
TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
Dmitri Shuralyov 2026-05-06 11:56:00 -04:00 committed by Gopher Robot
parent deee1b75cf
commit caeb5b7b66
3 changed files with 10 additions and 10 deletions

View file

@ -538,7 +538,6 @@ pkg encoding/json, type UnmarshalFieldError //deprecated
pkg go/build, const AllowBinary //deprecated
pkg go/doc, type Package struct, Bugs //deprecated
pkg go/importer, func For //deprecated
pkg go/importer, func ForCompiler //deprecated
pkg go/types, func NewInterface //deprecated
pkg go/types, method (*Interface) Embedded //deprecated
pkg image, var ZP //deprecated

View file

@ -1153,14 +1153,15 @@ func needApproval(filename string) bool {
func (w *Walker) collectDeprecated() {
isDeprecated := func(doc *ast.CommentGroup) bool {
if doc != nil {
for _, c := range doc.List {
if strings.HasPrefix(c.Text, "// Deprecated:") {
return true
}
}
}
return false
// Look for "Deprecated:" (case-sensitive) at the beginning (not middle) of a paragraph.
// It's typically found in the last paragraph, but it's not required to be the last one.
// The colon is typically followed by a space, but it can also be a newline, as was the
// case at https://go.dev/pkg/go/build#AllowBinary for example.
//
// See https://go.dev/wiki/Deprecated and https://go.dev/ref/mod#go-mod-file-module-deprecation.
text := doc.Text()
return strings.HasPrefix(text, "Deprecated: ") || strings.Contains(text, "\n\nDeprecated: ") ||
strings.HasPrefix(text, "Deprecated:\n") || strings.Contains(text, "\n\nDeprecated:\n")
}
w.deprecated = make(map[token.Pos]bool)

View file

@ -1,5 +1,5 @@
pkg issue79145, const Tau //deprecated
pkg issue79145, const Tau = 6.28319 // 314159265358979323846264338327950288419716939937510582097494459/50000000000000000000000000000000000000000000000000000000000000
pkg issue79145, const Tau ideal-float
pkg issue79145, const Old //deprecated
pkg issue79145, const Old = true
pkg issue79145, const Old ideal-bool