diff --git a/Makefile b/Makefile index 7248fae..1b1376d 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ export GOBIN ?= $(shell pwd)/bin GOLINT = $(GOBIN)/golint GEN_ATOMICINT = $(GOBIN)/gen-atomicint GEN_ATOMICWRAPPER = $(GOBIN)/gen-atomicwrapper +STATICCHECK = $(GOBIN)/staticcheck GO_FILES ?= $(shell find . '(' -path .git -o -path vendor ')' -prune -o -name '*.go' -print) @@ -29,6 +30,9 @@ gofmt: $(GOLINT): cd tools && go install golang.org/x/lint/golint +$(STATICCHECK): + cd tools && go install honnef.co/go/tools/cmd/staticcheck + $(GEN_ATOMICWRAPPER): $(wildcard ./internal/gen-atomicwrapper/*) go build -o $@ ./internal/gen-atomicwrapper @@ -39,8 +43,12 @@ $(GEN_ATOMICINT): $(wildcard ./internal/gen-atomicint/*) golint: $(GOLINT) $(GOLINT) ./... +.PHONY: staticcheck +staticcheck: $(STATICCHECK) + $(STATICCHECK) ./... + .PHONY: lint -lint: gofmt golint generatenodirty +lint: gofmt golint staticcheck generatenodirty # comma separated list of packages to consider for code coverage. COVER_PKG = $(shell \ diff --git a/bool.go b/bool.go index 1bf3fa0..9cf1914 100644 --- a/bool.go +++ b/bool.go @@ -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 } diff --git a/duration.go b/duration.go index 30ed6aa..027cfcb 100644 --- a/duration.go +++ b/duration.go @@ -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 } diff --git a/error.go b/error.go index cedbc91..a6166fb 100644 --- a/error.go +++ b/error.go @@ -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 } diff --git a/float64.go b/float64.go index fb33e90..0719060 100644 --- a/float64.go +++ b/float64.go @@ -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 } diff --git a/int32.go b/int32.go index 357f178..18ae564 100644 --- a/int32.go +++ b/int32.go @@ -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 } diff --git a/int64.go b/int64.go index 8448018..2bcbbfa 100644 --- a/int64.go +++ b/int64.go @@ -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 } diff --git a/internal/gen-atomicint/main.go b/internal/gen-atomicint/main.go index 4ffcb94..211cd34 100644 --- a/internal/gen-atomicint/main.go +++ b/internal/gen-atomicint/main.go @@ -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 }} } diff --git a/internal/gen-atomicwrapper/main.go b/internal/gen-atomicwrapper/main.go index 0bb180e..862c411 100644 --- a/internal/gen-atomicwrapper/main.go +++ b/internal/gen-atomicwrapper/main.go @@ -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 }} } diff --git a/nocmp_test.go b/nocmp_test.go index 22a7e02..d4be166 100644 --- a/nocmp_test.go +++ b/nocmp_test.go @@ -77,17 +77,16 @@ 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(x{}).Size() + after := reflect.TypeOf(y{}).Size() assert.Equal(t, before, after, "expected nocmp to have no effect on struct 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{} diff --git a/stress_test.go b/stress_test.go index 3dc7852..da9969b 100644 --- a/stress_test.go +++ b/stress_test.go @@ -37,7 +37,7 @@ const ( var _stressTests = map[string]func() func(){ "i32/std": stressStdInt32, "i32": stressInt32, - "i64/std": stressStdInt32, + "i64/std": stressStdInt64, "i64": stressInt64, "u32/std": stressStdUint32, "u32": stressUint32, diff --git a/string.go b/string.go index 8e3ac35..225b7a2 100644 --- a/string.go +++ b/string.go @@ -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 } diff --git a/tools/go.mod b/tools/go.mod index c7c0fc4..6bc16f2 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -2,7 +2,7 @@ module go.uber.org/atomic/tools require ( golang.org/x/lint v0.0.0-20190930215403-16217165b5de - golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c // indirect + honnef.co/go/tools v0.0.1-2020.1.5 ) go 1.13 diff --git a/tools/go.sum b/tools/go.sum index f9e4a2f..5c151b4 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -1,12 +1,28 @@ +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c h1:IGkKhmfzcztjm6gYkykvu/NiS8kaqbCWAEWWAyf8J5U= -golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d h1:/iIZNFGxc/a7C3yWjGcnboV+Tkc7mxr+p6fDztwoxuM= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +honnef.co/go/tools v0.0.1-2020.1.5 h1:nI5egYTGJakVyOryqLs1cQO5dO0ksin5XXs2pspk75k= +honnef.co/go/tools v0.0.1-2020.1.5/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= diff --git a/tools/tools.go b/tools/tools.go index 3ddca55..b4b3a01 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -25,4 +25,5 @@ package tools import ( // Tools used during development. _ "golang.org/x/lint/golint" + _ "honnef.co/go/tools/cmd/staticcheck" ) diff --git a/uint32.go b/uint32.go index 3fbb696..a973aba 100644 --- a/uint32.go +++ b/uint32.go @@ -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 } diff --git a/uint64.go b/uint64.go index 7cec96b..3b6c71f 100644 --- a/uint64.go +++ b/uint64.go @@ -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 } diff --git a/value.go b/value.go index 5c32903..671f3a3 100644 --- a/value.go +++ b/value.go @@ -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 }