Skip to content

Commit 4b65372

Browse files
authored
noCopy implements sync.Locker (#1216)
noCopy is used by -copylocks checker from `go vet`. see golang/go#8005 (comment) for details. but it doesn't work from Go 1.11, because of golang/go@c2eba53 and golang/go#26165 -copylock now works with structs that implement sync.Locker. So, noCopy should implement sync.Locker.
1 parent 9942e21 commit 4b65372

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

utils.go

+6
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,12 @@ type noCopy struct{}
790790
// Lock is a no-op used by -copylocks checker from `go vet`.
791791
func (*noCopy) Lock() {}
792792

793+
// Unlock is a no-op used by -copylocks checker from `go vet`.
794+
// noCopy should implement sync.Locker from Go 1.11
795+
// https://github.com/golang/go/commit/c2eba53e7f80df21d51285879d51ab81bcfbf6bc
796+
// https://github.com/golang/go/issues/26165
797+
func (*noCopy) Unlock() {}
798+
793799
// atomicBool is a wrapper around uint32 for usage as a boolean value with
794800
// atomic access.
795801
type atomicBool struct {

utils_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ func TestAtomicBool(t *testing.T) {
228228
t.Fatal("Expected value to be false")
229229
}
230230

231-
ab._noCopy.Lock() // we've "tested" it ¯\_(ツ)_/¯
231+
// we've "tested" them ¯\_(ツ)_/¯
232+
ab._noCopy.Lock()
233+
defer ab._noCopy.Unlock()
232234
}
233235

234236
func TestAtomicError(t *testing.T) {

0 commit comments

Comments
 (0)