github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/staticcheck/sa6002/testdata/src/example.com/CheckSyncPoolValue/CheckSyncPoolValue.go (about)

     1  package pkg
     2  
     3  import (
     4  	"sync"
     5  	"unsafe"
     6  )
     7  
     8  type T1 struct {
     9  	x int
    10  }
    11  
    12  type T2 struct {
    13  	x int
    14  	y int
    15  }
    16  
    17  func fn() {
    18  	s := []int{}
    19  
    20  	v := sync.Pool{}
    21  	v.Put(s) //@ diag(`argument should be pointer-like`)
    22  	v.Put(&s)
    23  	v.Put(T1{}) //@ diag(`argument should be pointer-like`)
    24  	v.Put(T2{}) //@ diag(`argument should be pointer-like`)
    25  
    26  	p := &sync.Pool{}
    27  	p.Put(s) //@ diag(`argument should be pointer-like`)
    28  	p.Put(&s)
    29  
    30  	var i interface{}
    31  	p.Put(i)
    32  
    33  	var up unsafe.Pointer
    34  	p.Put(up)
    35  
    36  	var basic int
    37  	p.Put(basic) //@ diag(`argument should be pointer-like`)
    38  }
    39  
    40  func fn2() {
    41  	// https://github.com/dominikh/go-tools/issues/873
    42  	var pool sync.Pool
    43  	func() {
    44  		defer pool.Put([]byte{}) //@ diag(`argument should be pointer-like`)
    45  	}()
    46  }
    47  
    48  func fn3() {
    49  	var pool sync.Pool
    50  	defer pool.Put([]byte{}) //@ diag(`argument should be pointer-like`)
    51  	go pool.Put([]byte{})    //@ diag(`argument should be pointer-like`)
    52  }