From d25c6f02a7b562c51f40530cd2862fc30897c687 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Tue, 29 Apr 2025 17:27:36 +0800 Subject: [PATCH] all: not copy loop var for golang v1.22 (#1020) --- eth/downloader/downloader.go | 1 - eth/handler.go | 1 - eth/tracers/testing/calltrace_test.go | 3 --- node/api_test.go | 1 - node/node_test.go | 1 - node/rpcstack_test.go | 1 - p2p/peer.go | 1 - rlp/decode_test.go | 1 - rlp/rlpgen/gen_test.go | 1 - rpc/client_test.go | 1 - rpc/types_test.go | 1 - tests/state_test.go | 1 - 12 files changed, 14 deletions(-) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 6e362b397c..d207e9bca1 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -489,7 +489,6 @@ func (d *Downloader) spawnSync(fetchers []func() error) error { errc := make(chan error, len(fetchers)) d.cancelWg.Add(len(fetchers)) for _, fn := range fetchers { - fn := fn go func() { defer d.cancelWg.Done(); errc <- fn() }() } // Wait for the first error, then terminate the others. diff --git a/eth/handler.go b/eth/handler.go index 1d91474ae9..421044c21e 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -166,7 +166,6 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne continue } // Compatible; initialise the sub-protocol - version := version // Closure for the run manager.SubProtocols = append(manager.SubProtocols, p2p.Protocol{ Name: ProtocolName, Version: version, diff --git a/eth/tracers/testing/calltrace_test.go b/eth/tracers/testing/calltrace_test.go index 6915889cde..3856d4fe9b 100644 --- a/eth/tracers/testing/calltrace_test.go +++ b/eth/tracers/testing/calltrace_test.go @@ -75,7 +75,6 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) { if !strings.HasSuffix(file.Name(), ".json") { continue } - file := file // capture range variable t.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(t *testing.T) { t.Parallel() @@ -180,7 +179,6 @@ func BenchmarkTracers(b *testing.B) { if !strings.HasSuffix(file.Name(), ".json") { continue } - file := file // capture range variable b.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(b *testing.B) { blob, err := os.ReadFile(filepath.Join("..", "testdata", "call_tracer", file.Name())) if err != nil { @@ -259,7 +257,6 @@ func testContractTracer(tracerName string, dirPath string, t *testing.T) { if !strings.HasSuffix(file.Name(), ".json") { continue } - file := file // capture range variable t.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(t *testing.T) { t.Parallel() diff --git a/node/api_test.go b/node/api_test.go index 9a1beee866..9f95477472 100644 --- a/node/api_test.go +++ b/node/api_test.go @@ -244,7 +244,6 @@ func TestStartRPC(t *testing.T) { } for _, test := range tests { - test := test t.Run(test.name, func(t *testing.T) { t.Parallel() diff --git a/node/node_test.go b/node/node_test.go index dca2c8fb3d..48ca27ee1b 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -475,7 +475,6 @@ func TestNodeRPCPrefix(t *testing.T) { } for _, test := range tests { - test := test name := fmt.Sprintf("http=%s ws=%s", test.httpPrefix, test.wsPrefix) t.Run(name, func(t *testing.T) { cfg := &Config{ diff --git a/node/rpcstack_test.go b/node/rpcstack_test.go index 27e6a87fd6..1e9b835bf3 100644 --- a/node/rpcstack_test.go +++ b/node/rpcstack_test.go @@ -507,7 +507,6 @@ func TestGzipHandler(t *testing.T) { } for _, test := range tests { - test := test t.Run(test.name, func(t *testing.T) { srv := httptest.NewServer(newGzipHandler(test.handler)) defer srv.Close() diff --git a/p2p/peer.go b/p2p/peer.go index 730c62a6b4..6cabe89342 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -355,7 +355,6 @@ outer: func (p *Peer) startProtocols(writeStart <-chan struct{}, writeErr chan<- error) { p.wg.Add(len(p.running)) for _, proto := range p.running { - proto := proto proto.closed = p.closed proto.wstart = writeStart proto.werr = writeErr diff --git a/rlp/decode_test.go b/rlp/decode_test.go index 8cd40c44cc..48250656e8 100644 --- a/rlp/decode_test.go +++ b/rlp/decode_test.go @@ -308,7 +308,6 @@ func TestStreamReadBytes(t *testing.T) { } for _, test := range tests { - test := test name := fmt.Sprintf("input_%s/size_%d", test.input, test.size) t.Run(name, func(t *testing.T) { s := NewStream(bytes.NewReader(unhex(test.input)), 0) diff --git a/rlp/rlpgen/gen_test.go b/rlp/rlpgen/gen_test.go index 3b4f5df287..b4fabb3dc6 100644 --- a/rlp/rlpgen/gen_test.go +++ b/rlp/rlpgen/gen_test.go @@ -51,7 +51,6 @@ var tests = []string{"uints", "nil", "rawvalue", "optional", "bigint", "uint256" func TestOutput(t *testing.T) { for _, test := range tests { - test := test t.Run(test, func(t *testing.T) { inputFile := filepath.Join("testdata", test+".in.txt") outputFile := filepath.Join("testdata", test+".out.txt") diff --git a/rpc/client_test.go b/rpc/client_test.go index 326f1006d7..9a3a1b773d 100644 --- a/rpc/client_test.go +++ b/rpc/client_test.go @@ -776,7 +776,6 @@ func TestClientHTTP(t *testing.T) { wantResult = echoResult{"a", 1, new(echoArgs)} ) for i := range results { - i := i go func() { errc <- client.Call(&results[i], "test_echo", wantResult.String, wantResult.Int, wantResult.Args) }() diff --git a/rpc/types_test.go b/rpc/types_test.go index ccf6c59844..c777e98655 100644 --- a/rpc/types_test.go +++ b/rpc/types_test.go @@ -143,7 +143,6 @@ func TestBlockNumberOrHash_WithNumber_MarshalAndUnmarshal(t *testing.T) { {"finalized", int64(CommittedBlockNumber)}, } for _, test := range tests { - test := test t.Run(test.name, func(t *testing.T) { bnh := BlockNumberOrHashWithNumber(BlockNumber(test.number)) marshalled, err := json.Marshal(bnh) diff --git a/tests/state_test.go b/tests/state_test.go index a834188215..871c1f347a 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -54,7 +54,6 @@ func TestState(t *testing.T) { st.walk(t, stateTestDir, func(t *testing.T, name string, test *StateTest) { for _, subtest := range test.Subtests() { - subtest := subtest key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index) name := name + "/" + key t.Run(key, func(t *testing.T) {