diff options
author | Alan Donovan <adonovan@google.com> | 2024-01-05 15:54:03 -0500 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2024-01-10 20:16:07 +0000 |
commit | 2540b1436ff452529b1668a8310411ddea826c52 (patch) | |
tree | 3d24ade1ebf5bd540f39c13fdcd49e124e286f0e | |
parent | 7e34c4308f1f48f3d817779797729c75b695f492 (diff) | |
download | go-2540b1436ff452529b1668a8310411ddea826c52.tar.gz go-2540b1436ff452529b1668a8310411ddea826c52.zip |
[release-branch.go1.21] slices: explicitly discard results of some functions
This will otherwise trigger an "unusedresult" vet check.
For #64978.
Fixes #65023.
Fixes #60058.
Change-Id: Ie19aded0f808d394f389452c3ff7f3edc1ed710d
Reviewed-on: https://go-review.googlesource.com/c/go/+/554196
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
(cherry picked from commit 8088b6db2341e6efdb9e0b0f43953ccd17fd9705)
Reviewed-on: https://go-review.googlesource.com/c/go/+/554756
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
-rw-r--r-- | src/slices/slices_test.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/slices/slices_test.go b/src/slices/slices_test.go index e6da3b0e03..6984f27a11 100644 --- a/src/slices/slices_test.go +++ b/src/slices/slices_test.go @@ -649,7 +649,7 @@ func TestDeletePanics(t *testing.T) { {"with out-of-bounds second index", []int{42}, 0, 2}, {"with invalid i>j", []int{42}, 1, 0}, } { - if !panics(func() { Delete(test.s, test.i, test.j) }) { + if !panics(func() { _ = Delete(test.s, test.i, test.j) }) { t.Errorf("Delete %s: got no panic, want panic", test.name) } } @@ -791,10 +791,10 @@ func TestGrow(t *testing.T) { } // Test number of allocations. - if n := testing.AllocsPerRun(100, func() { Grow(s2, cap(s2)-len(s2)) }); n != 0 { + if n := testing.AllocsPerRun(100, func() { _ = Grow(s2, cap(s2)-len(s2)) }); n != 0 { t.Errorf("Grow should not allocate when given sufficient capacity; allocated %v times", n) } - if n := testing.AllocsPerRun(100, func() { Grow(s2, cap(s2)-len(s2)+1) }); n != 1 { + if n := testing.AllocsPerRun(100, func() { _ = Grow(s2, cap(s2)-len(s2)+1) }); n != 1 { errorf := t.Errorf if race.Enabled || testenv.OptimizationOff() { errorf = t.Logf // this allocates multiple times in race detector mode @@ -806,7 +806,7 @@ func TestGrow(t *testing.T) { var gotPanic bool func() { defer func() { gotPanic = recover() != nil }() - Grow(s1, -1) + _ = Grow(s1, -1) }() if !gotPanic { t.Errorf("Grow(-1) did not panic; expected a panic") @@ -917,7 +917,7 @@ func TestReplacePanics(t *testing.T) { {"negative index", []int{1, 2}, []int{3}, -1, 2}, } { ss, vv := Clone(test.s), Clone(test.v) - if !panics(func() { Replace(ss, test.i, test.j, vv...) }) { + if !panics(func() { _ = Replace(ss, test.i, test.j, vv...) }) { t.Errorf("Replace %s: should have panicked", test.name) } } |