github.com/azazeal/revive@v1.0.9/testdata/atomic.go (about) 1 package fixtures 2 3 import ( 4 "sync/atomic" 5 ) 6 7 type Counter uint64 8 9 func AtomicTests() { 10 x := uint64(1) 11 x = atomic.AddUint64(&x, 1) // MATCH /direct assignment to atomic value/ 12 _, x = 10, atomic.AddUint64(&x, 1) // MATCH /direct assignment to atomic value/ 13 x, _ = atomic.AddUint64(&x, 1), 10 // MATCH /direct assignment to atomic value/ 14 15 y := &x 16 *y = atomic.AddUint64(y, 1) // MATCH /direct assignment to atomic value/ 17 18 var su struct{ Counter uint64 } 19 su.Counter = atomic.AddUint64(&su.Counter, 1) // MATCH /direct assignment to atomic value/ 20 z1 := atomic.AddUint64(&su.Counter, 1) 21 _ = z1 // Avoid err "z declared and not used" 22 23 var sp struct{ Counter *uint64 } 24 *sp.Counter = atomic.AddUint64(sp.Counter, 1) // MATCH /direct assignment to atomic value/ 25 z2 := atomic.AddUint64(sp.Counter, 1) 26 _ = z2 // Avoid err "z declared and not used" 27 28 au := []uint64{10, 20} 29 au[0] = atomic.AddUint64(&au[0], 1) // MATCH /direct assignment to atomic value/ 30 au[1] = atomic.AddUint64(&au[0], 1) 31 32 ap := []*uint64{&au[0], &au[1]} 33 *ap[0] = atomic.AddUint64(ap[0], 1) // MATCH /direct assignment to atomic value/ 34 *ap[1] = atomic.AddUint64(ap[0], 1) 35 } 36 37 type T struct{} 38 39 func (T) AddUint64(addr *uint64, delta uint64) uint64 { return 0 } 40 41 func NonAtomic() { 42 x := uint64(1) 43 var atomic T 44 x = atomic.AddUint64(&x, 1) // MATCH /direct assignment to atomic value/ 45 }