mirror of
https://github.com/golang/go
synced 2024-11-02 08:01:26 +00:00
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 <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
08176b28a3
commit
0c0c3c186b
2 changed files with 5 additions and 15 deletions
8
src/cmd/vet/testdata/copylock.go
vendored
8
src/cmd/vet/testdata/copylock.go
vendored
|
@ -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{}
|
||||
}
|
||||
|
|
|
@ -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() {}
|
||||
|
|
Loading…
Reference in a new issue