Skip to content

Commit a2473db

Browse files
authored
refactor: remove redundant variable declarations in for loops (#17657)
Inspired by #17147 and replace all. The new version of Go has been optimized, and variables do not need to be reassigned. For more info: https://tip.golang.org/wiki/LoopvarExperiment#does-this-mean-i-dont-have-to-write-x--x-in-my-loops-anymore Signed-off-by: pennylees <[email protected]>
1 parent 5f72608 commit a2473db

File tree

11 files changed

+0
-21
lines changed

11 files changed

+0
-21
lines changed

execution/abi/bind/util_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ func TestWaitDeployed(t *testing.T) {
6262
t.Skip("fix me on win please")
6363
}
6464
for name, test := range waitDeployedTests {
65-
name := name
66-
test := test
6765

6866
t.Run(name, func(t *testing.T) {
6967
backend := backends.NewSimulatedBackend(t,

execution/abi/unpack_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ func TestMethodMultiReturn(t *testing.T) {
380380
"Can not unpack into a slice with wrong types",
381381
}}
382382
for _, tc := range testCases {
383-
tc := tc
384383
t.Run(tc.name, func(t *testing.T) {
385384
require := require.New(t)
386385
err := abi.UnpackIntoInterface(tc.dest, "multi", data)

execution/consensus/clique/snapshot_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,6 @@ func TestClique(t *testing.T) {
399399
}
400400
// Run through the scenarios and test them
401401
for i, tt := range tests {
402-
i := i
403-
tt := tt
404402

405403
t.Run(tt.name, func(t *testing.T) {
406404
logger := testlog.Logger(t, log.LvlInfo)

execution/stages/genesis_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ func TestSetupGenesis(t *testing.T) {
171171
}
172172

173173
for _, test := range tests {
174-
test := test
175174
t.Run(test.name, func(t *testing.T) {
176175
t.Parallel()
177176
tmpdir := t.TempDir()

execution/stages/headerdownload/header_algo_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ func TestSideChainInsert(t *testing.T) {
9797
}
9898

9999
for _, tc := range testCases {
100-
tc := tc
101100
for i, h := range tc.chain {
102101
data, _ := rlp.EncodeToBytes(h)
103102
if _, err = hi.FeedHeaderPoW(tx, br, h, data, h.Hash(), uint64(i+1)); err != nil {

execution/stages/mock/accessors_indexes_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func TestLookupStorage(t *testing.T) {
5454
}
5555

5656
for _, tc := range tests {
57-
tc := tc
5857
t.Run(tc.name, func(t *testing.T) {
5958
t.Parallel()
6059
m := mock.Mock(t)

execution/state/rw_v3.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ func (rs *StateV3) applyUpdates(roTx kv.TemporalTx, blockNum, txNum uint64, stat
143143
var acc accounts.Account
144144
emptyRemoval := rules.IsSpuriousDragon
145145
for addr, increase := range balanceIncreases {
146-
increase := increase
147146
addrBytes := addr.Bytes()
148147
enc0, step0, err := domains.GetLatest(kv.AccountsDomain, roTx, addrBytes)
149148
if err != nil {

execution/tests/state_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func TestStateCornerCases(t *testing.T) {
5252
db := temporaltest.NewTestDB(t, dirs)
5353
st.walk(t, cornersDir, func(t *testing.T, name string, test *testutil.StateTest) {
5454
for _, subtest := range test.Subtests() {
55-
subtest := subtest
5655
key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index)
5756
t.Run(key, func(t *testing.T) {
5857
withTrace(t, func(vmconfig vm.Config) error {
@@ -101,7 +100,6 @@ func TestState(t *testing.T) {
101100
db := temporaltest.NewTestDB(t, dirs)
102101
st.walk(t, dir, func(t *testing.T, name string, test *testutil.StateTest) {
103102
for _, subtest := range test.Subtests() {
104-
subtest := subtest
105103
key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index)
106104
t.Run(key, func(t *testing.T) {
107105
withTrace(t, func(vmconfig vm.Config) error {

execution/types/accounts/account_benchmark_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func BenchmarkEncodingLengthForStorage(b *testing.B) {
6666

6767
b.ResetTimer()
6868
for _, test := range accountCases {
69-
test := test
7069
b.Run(fmt.Sprint(test.name), func(b *testing.B) {
7170
lengths := make([]uint, b.N)
7271

@@ -119,7 +118,6 @@ func BenchmarkEncodingLengthForHashing(b *testing.B) {
119118

120119
b.ResetTimer()
121120
for _, test := range accountCases {
122-
test := test
123121
b.Run(fmt.Sprint(test.name), func(bn *testing.B) {
124122
lengths := make([]uint, bn.N)
125123

@@ -174,7 +172,6 @@ func BenchmarkEncodingAccountForStorage(b *testing.B) {
174172

175173
b.ResetTimer()
176174
for _, test := range accountCases {
177-
test := test
178175

179176
//buf := make([]byte, test.acc.EncodingLengthForStorage())
180177
b.Run(fmt.Sprint(test.name), func(b *testing.B) {
@@ -230,7 +227,6 @@ func BenchmarkEncodingAccountForHashing(b *testing.B) {
230227

231228
b.ResetTimer()
232229
for _, test := range accountCases {
233-
test := test
234230
buf := make([]byte, test.acc.EncodingLengthForStorage())
235231
b.Run(fmt.Sprint(test.name), func(b *testing.B) {
236232
for i := 0; i < b.N; i++ {
@@ -285,7 +281,6 @@ func BenchmarkDecodingAccount(b *testing.B) {
285281
var decodedAccounts []Account
286282
b.ResetTimer()
287283
for _, test := range accountCases {
288-
test := test
289284
b.Run(fmt.Sprint(test.name), func(b *testing.B) {
290285
for i := 0; i < b.N; i++ {
291286
println(test.name, i, b.N) //TODO: it just stucks w/o that print
@@ -354,7 +349,6 @@ func BenchmarkDecodingIncarnation(b *testing.B) { // V2 version of bench was a p
354349
var decodedIncarnations []uint64
355350
b.ResetTimer()
356351
for _, test := range accountCases {
357-
test := test
358352
b.Run(fmt.Sprint(test.name), func(b *testing.B) {
359353
for i := 0; i < b.N; i++ {
360354
println(test.name, i, b.N) //TODO: it just stucks w/o that print
@@ -424,7 +418,6 @@ func BenchmarkRLPEncodingAccount(b *testing.B) {
424418

425419
b.ResetTimer()
426420
for _, test := range accountCases {
427-
test := test
428421
b.Run(fmt.Sprint(test.name), func(b *testing.B) {
429422
for i := 0; i < b.N; i++ {
430423
if err := test.acc.EncodeRLP(io.Discard); err != nil {

execution/types/receipt_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ func TestLegacyReceiptDecoding(t *testing.T) {
8686
receipt.Bloom = CreateBloom(Receipts{receipt})
8787

8888
for _, tc := range tests {
89-
tc := tc
9089
t.Run(tc.name, func(t *testing.T) {
9190
t.Parallel()
9291
enc, err := tc.encode(receipt)

0 commit comments

Comments
 (0)