]> Cypherpunks repositories - gostls13.git/commitdiff
sync/atomic: remove noCopy from Value
authorRuss Cox <rsc@golang.org>
Wed, 29 Nov 2017 21:20:50 +0000 (16:20 -0500)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 1 Dec 2017 16:38:53 +0000 (16:38 +0000)
Values must not be copied after the first use.

Using noCopy makes vet complain about copies
even before the first use, which is incorrect
and very frustrating.

Drop it.

Fixes #21504.

Change-Id: Icd3a5ac3fe11e84525b998e848ed18a5d996f45a
Reviewed-on: https://go-review.googlesource.com/80836
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/vet/testdata/copylock.go
src/sync/atomic/value.go

index d733488e6218b55778458d7ff37125c3e5a16787..e9902a27f10dd204a77138beb28aabdbefc946f3 100644 (file)
@@ -178,9 +178,11 @@ func AtomicTypesCheck() {
        var vX atomic.Value
        var vXX = atomic.Value{}
        vX1 := new(atomic.Value)
-       vY := vX     // ERROR "assignment copies lock value to vY: sync/atomic.Value contains sync/atomic.noCopy"
-       vY = vX      // ERROR "assignment copies lock value to vY: sync/atomic.Value contains sync/atomic.noCopy"
-       var vYY = vX // ERROR "variable declaration copies lock value to vYY: sync/atomic.Value contains sync/atomic.noCopy"
+       // These are OK because the value has not been used yet.
+       // (And vet can't tell whether it has been used, so they're always OK.)
+       vY := vX
+       vY = vX
+       var vYY = vX
        vP := &vX
        vZ := &atomic.Value{}
 }
index ac5a9a5e7228f72e0b807aaab51548be86857d17..eab7e70c9b0f3ed5155cbf3c6a9e73cb4154c2c8 100644 (file)
@@ -14,8 +14,6 @@ import (
 //
 // A Value must not be copied after first use.
 type Value struct {
-       noCopy noCopy
-
        v interface{}
 }
 
@@ -86,13 +84,3 @@ func (v *Value) Store(x interface{}) {
 // Disable/enable preemption, implemented in runtime.
 func runtime_procPin()
 func runtime_procUnpin()
-
-// noCopy may be embedded into structs which must not be copied
-// after the first use.
-//
-// See https://golang.org/issues/8005#issuecomment-190753527
-// for details.
-type noCopy struct{}
-
-// Lock is a no-op used by -copylocks checker from `go vet`.
-func (*noCopy) Lock() {}