Skip to content

Commit 0c0c3c1

Browse files
rscbradfitz
authored andcommitted
sync/atomic: remove noCopy from Value
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 08176b2 commit 0c0c3c1

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

src/cmd/vet/testdata/copylock.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,11 @@ func AtomicTypesCheck() {
178178
var vX atomic.Value
179179
var vXX = atomic.Value{}
180180
vX1 := new(atomic.Value)
181-
vY := vX // ERROR "assignment copies lock value to vY: sync/atomic.Value contains sync/atomic.noCopy"
182-
vY = vX // ERROR "assignment copies lock value to vY: sync/atomic.Value contains sync/atomic.noCopy"
183-
var vYY = vX // ERROR "variable declaration copies lock value to vYY: sync/atomic.Value contains sync/atomic.noCopy"
181+
// These are OK because the value has not been used yet.
182+
// (And vet can't tell whether it has been used, so they're always OK.)
183+
vY := vX
184+
vY = vX
185+
var vYY = vX
184186
vP := &vX
185187
vZ := &atomic.Value{}
186188
}

src/sync/atomic/value.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
//
1515
// A Value must not be copied after first use.
1616
type Value struct {
17-
noCopy noCopy
18-
1917
v interface{}
2018
}
2119

@@ -86,13 +84,3 @@ func (v *Value) Store(x interface{}) {
8684
// Disable/enable preemption, implemented in runtime.
8785
func runtime_procPin()
8886
func runtime_procUnpin()
89-
90-
// noCopy may be embedded into structs which must not be copied
91-
// after the first use.
92-
//
93-
// See https://golang.org/issues/8005#issuecomment-190753527
94-
// for details.
95-
type noCopy struct{}
96-
97-
// Lock is a no-op used by -copylocks checker from `go vet`.
98-
func (*noCopy) Lock() {}

0 commit comments

Comments
 (0)