staticcheck: Fix unused fields

The embedded `nocmp` field and other similar fields are unused in tests
and the rest of our code.

We can get the effect of `nocmp` without embedding the fields by using
`_ nocmp` as a field.
This commit is contained in:
Abhinav Gupta
2020-09-11 09:55:04 -07:00
parent 746c19c0c5
commit f64e592f7f
13 changed files with 17 additions and 17 deletions

View File

@@ -28,7 +28,7 @@ import (
// Bool is an atomic type-safe wrapper for bool values.
type Bool struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v Uint32
}

View File

@@ -29,7 +29,7 @@ import (
// Duration is an atomic type-safe wrapper for time.Duration values.
type Duration struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v Int64
}

View File

@@ -24,7 +24,7 @@ package atomic
// Error is an atomic type-safe wrapper for error values.
type Error struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v Value
}

View File

@@ -29,7 +29,7 @@ import (
// Float64 is an atomic type-safe wrapper for float64 values.
type Float64 struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v Uint64
}

View File

@@ -30,7 +30,7 @@ import (
// Int32 is an atomic wrapper around int32.
type Int32 struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v int32
}

View File

@@ -30,7 +30,7 @@ import (
// Int64 is an atomic wrapper around int64.
type Int64 struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v int64
}

View File

@@ -135,7 +135,7 @@ import (
// {{ .Name }} is an atomic wrapper around {{ .Wrapped }}.
type {{ .Name }} struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v {{ .Wrapped }}
}

View File

@@ -227,7 +227,7 @@ import (
// {{ .Name }} is an atomic type-safe wrapper for {{ .Type }} values.
type {{ .Name }} struct{
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v {{ .Wrapped }}
}

View File

@@ -77,14 +77,13 @@ func TestNocmpComparability(t *testing.T) {
// nocmp must not add to the size of a struct in-memory.
func TestNocmpSize(t *testing.T) {
type x struct{ i int }
type x struct{ _ int }
before := reflect.TypeOf(x{}).Size()
type y struct {
nocmp
x x
_ nocmp
_ x
}
after := reflect.TypeOf(y{}).Size()
@@ -100,7 +99,7 @@ func TestNocmpSize(t *testing.T) {
// var x atomic.Int32
// x = atomic.NewInt32(1)
func TestNocmpCopy(t *testing.T) {
type foo struct{ nocmp }
type foo struct{ _ nocmp }
t.Run("struct copy", func(t *testing.T) {
a := foo{}

View File

@@ -24,7 +24,7 @@ package atomic
// String is an atomic type-safe wrapper for string values.
type String struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v Value
}

View File

@@ -30,7 +30,7 @@ import (
// Uint32 is an atomic wrapper around uint32.
type Uint32 struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v uint32
}

View File

@@ -30,7 +30,7 @@ import (
// Uint64 is an atomic wrapper around uint64.
type Uint64 struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v uint64
}

View File

@@ -25,6 +25,7 @@ import "sync/atomic"
// Value shadows the type of the same name from sync/atomic
// https://godoc.org/sync/atomic#Value
type Value struct {
nocmp // disallow non-atomic comparison
atomic.Value
_ nocmp // disallow non-atomic comparison
}