From 646af74dfe254df0277da2447c6699717558c479 Mon Sep 17 00:00:00 2001 From: Ichinose Shogo Date: Wed, 26 May 2021 12:54:56 +0900 Subject: [PATCH] noCopy implements sync.Locker noCopy is used by -copylocks checker from `go vet`. see https://github.com/golang/go/issues/8005#issuecomment-190753527 for details. but it doesn't work from Go 1.11, because of https://github.com/golang/go/commit/c2eba53e7f80df21d51285879d51ab81bcfbf6bc and https://github.com/golang/go/issues/26165 -copylock now works with structs that implement sync.Locker. So, noCopy should implement sync.Locker. --- utils.go | 6 ++++++ utils_test.go | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/utils.go b/utils.go index d6545f5be..b400cf99f 100644 --- a/utils.go +++ b/utils.go @@ -790,6 +790,12 @@ type noCopy struct{} // Lock is a no-op used by -copylocks checker from `go vet`. func (*noCopy) Lock() {} +// Unlock is a no-op used by -copylocks checker from `go vet`. +// noCopy should implement sync.Locker from Go 1.11 +// https://github.com/golang/go/commit/c2eba53e7f80df21d51285879d51ab81bcfbf6bc +// https://github.com/golang/go/issues/26165 +func (*noCopy) Unlock() {} + // atomicBool is a wrapper around uint32 for usage as a boolean value with // atomic access. type atomicBool struct { diff --git a/utils_test.go b/utils_test.go index 67b132d2b..b0069251e 100644 --- a/utils_test.go +++ b/utils_test.go @@ -228,7 +228,9 @@ func TestAtomicBool(t *testing.T) { t.Fatal("Expected value to be false") } - ab._noCopy.Lock() // we've "tested" it ¯\_(ツ)_/¯ + // we've "tested" them ¯\_(ツ)_/¯ + ab._noCopy.Lock() + defer ab._noCopy.Unlock() } func TestAtomicError(t *testing.T) {