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. // Bool is an atomic type-safe wrapper for bool values.
type Bool struct { type Bool struct {
nocmp // disallow non-atomic comparison _ nocmp // disallow non-atomic comparison
v Uint32 v Uint32
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -227,7 +227,7 @@ import (
// {{ .Name }} is an atomic type-safe wrapper for {{ .Type }} values. // {{ .Name }} is an atomic type-safe wrapper for {{ .Type }} values.
type {{ .Name }} struct{ type {{ .Name }} struct{
nocmp // disallow non-atomic comparison _ nocmp // disallow non-atomic comparison
v {{ .Wrapped }} 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. // nocmp must not add to the size of a struct in-memory.
func TestNocmpSize(t *testing.T) { func TestNocmpSize(t *testing.T) {
type x struct{ i int } type x struct{ _ int }
before := reflect.TypeOf(x{}).Size() before := reflect.TypeOf(x{}).Size()
type y struct { type y struct {
nocmp _ nocmp
_ x
x x
} }
after := reflect.TypeOf(y{}).Size() after := reflect.TypeOf(y{}).Size()
@@ -100,7 +99,7 @@ func TestNocmpSize(t *testing.T) {
// var x atomic.Int32 // var x atomic.Int32
// x = atomic.NewInt32(1) // x = atomic.NewInt32(1)
func TestNocmpCopy(t *testing.T) { func TestNocmpCopy(t *testing.T) {
type foo struct{ nocmp } type foo struct{ _ nocmp }
t.Run("struct copy", func(t *testing.T) { t.Run("struct copy", func(t *testing.T) {
a := foo{} a := foo{}

View File

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

View File

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

View File

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

View File

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