]> Cypherpunks repositories - gostls13.git/commitdiff
slices,sort: explicitly discard results in benchmarks
authorAlan Donovan <adonovan@google.com>
Mon, 2 Jun 2025 15:27:08 +0000 (11:27 -0400)
committerAlan Donovan <adonovan@google.com>
Mon, 2 Jun 2025 16:09:25 +0000 (09:09 -0700)
The unusedresult analyzer will report failure to use the results
of these pure functions.

Updates #73950

Change-Id: I783cb92ad913105afd46c782bedf6234410c645d
Reviewed-on: https://go-review.googlesource.com/c/go/+/677995
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/slices/sort_benchmark_test.go
src/slices/sort_test.go
src/sort/sort_slices_benchmark_test.go

index 1dde26ef1c1bc4da2b7cdbb8a90de2c20a6bdaa3..cafb1a46187af45f56711750eaeb26d5a10d7e9c 100644 (file)
@@ -23,7 +23,7 @@ func BenchmarkBinarySearchFloats(b *testing.B) {
                        needle := (floats[midpoint] + floats[midpoint+1]) / 2
                        b.ResetTimer()
                        for i := 0; i < b.N; i++ {
-                               slices.BinarySearch(floats, needle)
+                               _, _ = slices.BinarySearch(floats, needle)
                        }
                })
        }
@@ -46,7 +46,7 @@ func BenchmarkBinarySearchFuncStruct(b *testing.B) {
                        cmpFunc := func(a, b *myStruct) int { return a.n - b.n }
                        b.ResetTimer()
                        for i := 0; i < b.N; i++ {
-                               slices.BinarySearchFunc(structs, needle, cmpFunc)
+                               _, _ = slices.BinarySearchFunc(structs, needle, cmpFunc)
                        }
                })
        }
index 2e045e2af8893955ac924a92151e942cd6982d2c..855f861c514bd57fa35578e4c09404f5f69d242c 100644 (file)
@@ -264,19 +264,19 @@ func TestMinMaxPanics(t *testing.T) {
        intCmp := func(a, b int) int { return a - b }
        emptySlice := []int{}
 
-       if !panics(func() { Min(emptySlice) }) {
+       if !panics(func() { _ = Min(emptySlice) }) {
                t.Errorf("Min([]): got no panic, want panic")
        }
 
-       if !panics(func() { Max(emptySlice) }) {
+       if !panics(func() { _ = Max(emptySlice) }) {
                t.Errorf("Max([]): got no panic, want panic")
        }
 
-       if !panics(func() { MinFunc(emptySlice, intCmp) }) {
+       if !panics(func() { _ = MinFunc(emptySlice, intCmp) }) {
                t.Errorf("MinFunc([]): got no panic, want panic")
        }
 
-       if !panics(func() { MaxFunc(emptySlice, intCmp) }) {
+       if !panics(func() { _ = MaxFunc(emptySlice, intCmp) }) {
                t.Errorf("MaxFunc([]): got no panic, want panic")
        }
 }
index 069536df03b33ceea1ae2cbc59fcfc9805c9e268..6fea511284570fa3af9c234f2690f572bba6f51d 100644 (file)
@@ -85,7 +85,7 @@ func BenchmarkSlicesIsSorted(b *testing.B) {
                b.StopTimer()
                ints := makeSortedInts(N)
                b.StartTimer()
-               slices.IsSorted(ints)
+               _ = slices.IsSorted(ints)
        }
 }