[tools] go/analysis/passes/modernize: moderniser for iterator APIs

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Oct 7, 2025, 5:22:24 PM (15 hours ago) Oct 7
to Alan Donovan, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Robert Findley, Mateusz Poliwczak, Austin Clements, golang-co...@googlegroups.com

Gopher Robot submitted the change

Unreviewed changes

7 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.

Change information

Commit message:
go/analysis/passes/modernize: modernizer for iterator APIs

This CL adds the stditerators modernizer, which replaces loops
of the form

for i := 0; i < x.Len(); i++ {
use(x.At(i))
}

or their "range x.Len()" equivalent by

for elem := range x.All() {
use(x.At(i)
}

for various well-known std types.

Publishing each new Analyzer symbol requires going through the
proposal process, so we plan to do them in one batch per Go
release. In the interim, we cannot make such symbols public,
so we use a backdoor mechanism to export them to gopls.

+ test, doc, relnote

Updates golang/go#75693
Change-Id: I3accd1925ad990b84500a9e77c3c589aeaeabfb0
Reviewed-by: Robert Findley <rfin...@google.com>
Auto-Submit: Alan Donovan <adon...@google.com>
Files:
  • M go/analysis/passes/modernize/bloop.go
  • M go/analysis/passes/modernize/doc.go
  • M go/analysis/passes/modernize/modernize.go
  • M go/analysis/passes/modernize/modernize_test.go
  • A go/analysis/passes/modernize/stditerators.go
  • A go/analysis/passes/modernize/testdata/src/stditerators/stditerators.go
  • A go/analysis/passes/modernize/testdata/src/stditerators/stditerators.go.golden
  • M gopls/doc/analyzers.md
  • M gopls/doc/release/v0.21.0.md
  • M gopls/internal/doc/api.json
  • M gopls/internal/settings/analysis.go
  • A internal/goplsexport/export.go
Change size: L
Delta: 12 files changed, 580 insertions(+), 9 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Robert Findley
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I3accd1925ad990b84500a9e77c3c589aeaeabfb0
Gerrit-Change-Number: 708775
Gerrit-PatchSet: 9
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Robert Findley <rfin...@google.com>
Gerrit-CC: Austin Clements <aus...@google.com>
Gerrit-CC: Mateusz Poliwczak <mpoliw...@gmail.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages