From a6a4a41e225096a2599762d95af9c32d944a15e2 Mon Sep 17 00:00:00 2001 From: Ariel Otilibili Date: Tue, 24 Feb 2026 01:22:37 +0000 Subject: all: test: remove unneeded loop variables This CL follows from the abandoned CL 722961. Alan Donovan asked if modernize would catch these changes; it does in part. Here is how modernize was used: 1. Build the Go compiler from latest master 2. Clone x/tools and build modernize with the newest compiler 3. Then, do: PATH=PATH_TO_BIN:$PATH go list ./... | xargs env PATH=PATH_TO_BIN:$PATH GOMOD=off MODERNIZE -forvar -fix -test -debug fpstv 4. For assurance, move into a package directory (i.e, cmd), and redo Step 3. From the obtained result, it seems modernize did not remove the loop variable when: - the range notation was not used - the loop variable was not directly under the for directive. Which does happens here: # git ls-files | xargs -I {} perl -nE 'print "$ARGV:$.:$_" if /\s+(\w+) := \1$/' {} | grep _test [...] cmd/compile/internal/types2/api_test.go:2423: i := i md/go/internal/modload/query_test.go:182: tt := tt md/go/internal/web/url_test.go:17: tc := tc cmd/go/internal/web/url_test.go:49: tc := tc cmd/internal/par/queue_test.go:54: i := i runtime/syscall_windows_test.go:781: arglen := arglen Link: https://go-review.googlesource.com/c/go/+/722961/comments/e8d47866_fc399fa1 Co-authored-by: Plamerdi Makela Fixes #76411 Change-Id: I0c191cdca70dbea6efaf6796dca9c60e2afcd9ea GitHub-Last-Rev: 77c3e11fc21a4ede70b733b567a1690edb944dc1 GitHub-Pull-Request: golang/go#77694 Reviewed-on: https://go-review.googlesource.com/c/go/+/746502 Auto-Submit: Jorropo Reviewed-by: David Chase Reviewed-by: Jorropo LUCI-TryBot-Result: Go LUCI Reviewed-by: Alan Donovan --- src/cmd/api/api_test.go | 1 - src/cmd/api/main_test.go | 1 - 2 files changed, 2 deletions(-) (limited to 'src/cmd/api') diff --git a/src/cmd/api/api_test.go b/src/cmd/api/api_test.go index 98ebf168ef..784bdb74e4 100644 --- a/src/cmd/api/api_test.go +++ b/src/cmd/api/api_test.go @@ -232,7 +232,6 @@ var warmupCache = sync.OnceFunc(func() { // Warm up the import cache in parallel. var wg sync.WaitGroup for _, context := range contexts { - context := context wg.Add(1) go func() { defer wg.Done() diff --git a/src/cmd/api/main_test.go b/src/cmd/api/main_test.go index ed366be4e7..7917423eac 100644 --- a/src/cmd/api/main_test.go +++ b/src/cmd/api/main_test.go @@ -121,7 +121,6 @@ func Check(t *testing.T) { walkers := make([]*Walker, len(contexts)) var wg sync.WaitGroup for i, context := range contexts { - i, context := i, context wg.Add(1) go func() { defer wg.Done() -- cgit v1.3-6-g1900