aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeschi Kreinick <heschi@google.com>2023-06-21 16:40:48 -0400
committerGopher Robot <gobot@golang.org>2023-06-21 21:25:57 +0000
commitc32f1afb4147a7380d9c2efa8503434198190b3a (patch)
tree12af8009d16c5af33d50d1ada86d6abd0312d388
parentc7b145655b0e7feeff65bee202eda849fa3e3452 (diff)
downloadgo-c32f1afb4147a7380d9c2efa8503434198190b3a.tar.gz
go-c32f1afb4147a7380d9c2efa8503434198190b3a.zip
[release-branch.go1.20] all: make safe for new vet analyzer
The unused analyzer handles dot imports now, so a few tests have picked up vet errors. This CL errors like: context/x_test.go:524:47: result of context.WithValue call not used This is a manual cherry-pick of CL 493598. Updates #60058 Fixes #60927 Change-Id: I92906ef7967e14a85fa974e6307fd689e3ff3dba Reviewed-on: https://go-review.googlesource.com/c/go/+/504977 Auto-Submit: Heschi Kreinick <heschi@google.com> TryBot-Bypass: Heschi Kreinick <heschi@google.com> Run-TryBot: Heschi Kreinick <heschi@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
-rw-r--r--src/context/context_test.go10
-rw-r--r--src/fmt/fmt_test.go56
2 files changed, 33 insertions, 33 deletions
diff --git a/src/context/context_test.go b/src/context/context_test.go
index eb5a86b3c6..1c770cdec8 100644
--- a/src/context/context_test.go
+++ b/src/context/context_test.go
@@ -670,26 +670,26 @@ func XTestWithCancelCanceledParent(t testingT) {
}
func XTestWithValueChecksKey(t testingT) {
- panicVal := recoveredValue(func() { WithValue(Background(), []byte("foo"), "bar") })
+ panicVal := recoveredValue(func() { _ = WithValue(Background(), []byte("foo"), "bar") })
if panicVal == nil {
t.Error("expected panic")
}
- panicVal = recoveredValue(func() { WithValue(Background(), nil, "bar") })
+ panicVal = recoveredValue(func() { _ = WithValue(Background(), nil, "bar") })
if got, want := fmt.Sprint(panicVal), "nil key"; got != want {
t.Errorf("panic = %q; want %q", got, want)
}
}
func XTestInvalidDerivedFail(t testingT) {
- panicVal := recoveredValue(func() { WithCancel(nil) })
+ panicVal := recoveredValue(func() { _, _ = WithCancel(nil) })
if panicVal == nil {
t.Error("expected panic")
}
- panicVal = recoveredValue(func() { WithDeadline(nil, time.Now().Add(shortDuration)) })
+ panicVal = recoveredValue(func() { _, _ = WithDeadline(nil, time.Now().Add(shortDuration)) })
if panicVal == nil {
t.Error("expected panic")
}
- panicVal = recoveredValue(func() { WithValue(nil, "foo", "bar") })
+ panicVal = recoveredValue(func() { _ = WithValue(nil, "foo", "bar") })
if panicVal == nil {
t.Error("expected panic")
}
diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go
index 37d82acbf4..6a79862f28 100644
--- a/src/fmt/fmt_test.go
+++ b/src/fmt/fmt_test.go
@@ -1238,7 +1238,7 @@ func TestReorder(t *testing.T) {
func BenchmarkSprintfPadding(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%16f", 1.0)
+ _ = Sprintf("%16f", 1.0)
}
})
}
@@ -1246,7 +1246,7 @@ func BenchmarkSprintfPadding(b *testing.B) {
func BenchmarkSprintfEmpty(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("")
+ _ = Sprintf("")
}
})
}
@@ -1254,7 +1254,7 @@ func BenchmarkSprintfEmpty(b *testing.B) {
func BenchmarkSprintfString(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%s", "hello")
+ _ = Sprintf("%s", "hello")
}
})
}
@@ -1262,7 +1262,7 @@ func BenchmarkSprintfString(b *testing.B) {
func BenchmarkSprintfTruncateString(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%.3s", "日本語日本語日本語日本語")
+ _ = Sprintf("%.3s", "日本語日本語日本語日本語")
}
})
}
@@ -1271,7 +1271,7 @@ func BenchmarkSprintfTruncateBytes(b *testing.B) {
var bytes any = []byte("日本語日本語日本語日本語")
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%.3s", bytes)
+ _ = Sprintf("%.3s", bytes)
}
})
}
@@ -1279,7 +1279,7 @@ func BenchmarkSprintfTruncateBytes(b *testing.B) {
func BenchmarkSprintfSlowParsingPath(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%.v", nil)
+ _ = Sprintf("%.v", nil)
}
})
}
@@ -1287,7 +1287,7 @@ func BenchmarkSprintfSlowParsingPath(b *testing.B) {
func BenchmarkSprintfQuoteString(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%q", "日本語日本語日本語")
+ _ = Sprintf("%q", "日本語日本語日本語")
}
})
}
@@ -1295,7 +1295,7 @@ func BenchmarkSprintfQuoteString(b *testing.B) {
func BenchmarkSprintfInt(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%d", 5)
+ _ = Sprintf("%d", 5)
}
})
}
@@ -1303,7 +1303,7 @@ func BenchmarkSprintfInt(b *testing.B) {
func BenchmarkSprintfIntInt(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%d %d", 5, 6)
+ _ = Sprintf("%d %d", 5, 6)
}
})
}
@@ -1311,7 +1311,7 @@ func BenchmarkSprintfIntInt(b *testing.B) {
func BenchmarkSprintfPrefixedInt(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("This is some meaningless prefix text that needs to be scanned %d", 6)
+ _ = Sprintf("This is some meaningless prefix text that needs to be scanned %d", 6)
}
})
}
@@ -1319,7 +1319,7 @@ func BenchmarkSprintfPrefixedInt(b *testing.B) {
func BenchmarkSprintfFloat(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%g", 5.23184)
+ _ = Sprintf("%g", 5.23184)
}
})
}
@@ -1327,7 +1327,7 @@ func BenchmarkSprintfFloat(b *testing.B) {
func BenchmarkSprintfComplex(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%f", 5.23184+5.23184i)
+ _ = Sprintf("%f", 5.23184+5.23184i)
}
})
}
@@ -1335,7 +1335,7 @@ func BenchmarkSprintfComplex(b *testing.B) {
func BenchmarkSprintfBoolean(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%t", true)
+ _ = Sprintf("%t", true)
}
})
}
@@ -1343,7 +1343,7 @@ func BenchmarkSprintfBoolean(b *testing.B) {
func BenchmarkSprintfHexString(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("% #x", "0123456789abcdef")
+ _ = Sprintf("% #x", "0123456789abcdef")
}
})
}
@@ -1352,7 +1352,7 @@ func BenchmarkSprintfHexBytes(b *testing.B) {
data := []byte("0123456789abcdef")
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("% #x", data)
+ _ = Sprintf("% #x", data)
}
})
}
@@ -1361,7 +1361,7 @@ func BenchmarkSprintfBytes(b *testing.B) {
data := []byte("0123456789abcdef")
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%v", data)
+ _ = Sprintf("%v", data)
}
})
}
@@ -1370,7 +1370,7 @@ func BenchmarkSprintfStringer(b *testing.B) {
stringer := I(12345)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%v", stringer)
+ _ = Sprintf("%v", stringer)
}
})
}
@@ -1379,7 +1379,7 @@ func BenchmarkSprintfStructure(b *testing.B) {
s := &[]any{SI{12345}, map[int]string{0: "hello"}}
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- Sprintf("%#v", s)
+ _ = Sprintf("%#v", s)
}
})
}
@@ -1428,14 +1428,14 @@ var mallocTest = []struct {
desc string
fn func()
}{
- {0, `Sprintf("")`, func() { Sprintf("") }},
- {1, `Sprintf("xxx")`, func() { Sprintf("xxx") }},
- {0, `Sprintf("%x")`, func() { Sprintf("%x", 7) }},
- {1, `Sprintf("%x")`, func() { Sprintf("%x", 1<<16) }},
- {3, `Sprintf("%80000s")`, func() { Sprintf("%80000s", "hello") }}, // large buffer (>64KB)
- {1, `Sprintf("%s")`, func() { Sprintf("%s", "hello") }},
- {1, `Sprintf("%x %x")`, func() { Sprintf("%x %x", 7, 112) }},
- {1, `Sprintf("%g")`, func() { Sprintf("%g", float32(3.14159)) }},
+ {0, `Sprintf("")`, func() { _ = Sprintf("") }},
+ {1, `Sprintf("xxx")`, func() { _ = Sprintf("xxx") }},
+ {0, `Sprintf("%x")`, func() { _ = Sprintf("%x", 7) }},
+ {1, `Sprintf("%x")`, func() { _ = Sprintf("%x", 1<<16) }},
+ {3, `Sprintf("%80000s")`, func() { _ = Sprintf("%80000s", "hello") }}, // large buffer (>64KB)
+ {1, `Sprintf("%s")`, func() { _ = Sprintf("%s", "hello") }},
+ {1, `Sprintf("%x %x")`, func() { _ = Sprintf("%x %x", 7, 112) }},
+ {1, `Sprintf("%g")`, func() { _ = Sprintf("%g", float32(3.14159)) }},
{0, `Fprintf(buf, "%s")`, func() { mallocBuf.Reset(); Fprintf(&mallocBuf, "%s", "hello") }},
{0, `Fprintf(buf, "%x")`, func() { mallocBuf.Reset(); Fprintf(&mallocBuf, "%x", 7) }},
{0, `Fprintf(buf, "%x")`, func() { mallocBuf.Reset(); Fprintf(&mallocBuf, "%x", 1<<16) }},
@@ -1773,13 +1773,13 @@ func (r *Recur) String() string {
func TestBadVerbRecursion(t *testing.T) {
failed := false
r := &Recur{3, &failed}
- Sprintf("recur@%p value: %d\n", &r, r.i)
+ _ = Sprintf("recur@%p value: %d\n", &r, r.i)
if failed {
t.Error("fail with pointer")
}
failed = false
r = &Recur{4, &failed}
- Sprintf("recur@%p, value: %d\n", r, r.i)
+ _ = Sprintf("recur@%p, value: %d\n", r, r.i)
if failed {
t.Error("fail with value")
}