aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Donovan <adonovan@google.com>2025-06-02 11:27:08 -0400
committerAlan Donovan <adonovan@google.com>2025-06-02 09:09:25 -0700
commite9d3b030ed6fe8380d9b0411ef06eff001769641 (patch)
tree91835f600328d4b44097462e82fbc6a208b78aad
parenta8e99ab19cbf8568cb452b899d0ed3f0d65848c5 (diff)
downloadgo-e9d3b030ed6fe8380d9b0411ef06eff001769641.tar.xz
slices,sort: explicitly discard results in benchmarks
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>
-rw-r--r--src/slices/sort_benchmark_test.go4
-rw-r--r--src/slices/sort_test.go8
-rw-r--r--src/sort/sort_slices_benchmark_test.go2
3 files changed, 7 insertions, 7 deletions
diff --git a/src/slices/sort_benchmark_test.go b/src/slices/sort_benchmark_test.go
index 1dde26ef1c..cafb1a4618 100644
--- a/src/slices/sort_benchmark_test.go
+++ b/src/slices/sort_benchmark_test.go
@@ -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)
}
})
}
diff --git a/src/slices/sort_test.go b/src/slices/sort_test.go
index 2e045e2af8..855f861c51 100644
--- a/src/slices/sort_test.go
+++ b/src/slices/sort_test.go
@@ -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")
}
}
diff --git a/src/sort/sort_slices_benchmark_test.go b/src/sort/sort_slices_benchmark_test.go
index 069536df03..6fea511284 100644
--- a/src/sort/sort_slices_benchmark_test.go
+++ b/src/sort/sort_slices_benchmark_test.go
@@ -85,7 +85,7 @@ func BenchmarkSlicesIsSorted(b *testing.B) {
b.StopTimer()
ints := makeSortedInts(N)
b.StartTimer()
- slices.IsSorted(ints)
+ _ = slices.IsSorted(ints)
}
}