github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/simple/s1001/testdata/src/example.com/CheckLoopCopy/copy_generics.go.golden (about) 1 //go:build go1.20 2 3 package pkg 4 5 func tpfn[T any]() { 6 var b1, b2 []T 7 copy(b2, b1) 8 9 copy(b2, b1) 10 11 type T2 [][16]T 12 var a T2 13 b := make([]any, len(a)) 14 for i := range b { 15 b[i] = a[i] 16 } 17 18 var b3, b4 []*T 19 copy(b4, b3) 20 21 var m map[int]T 22 for i, v := range b1 { 23 m[i] = v 24 } 25 26 } 27 28 func tpsrc[T any]() []T { return nil } 29 30 func tpfn1() { 31 // Don't flag this, the source is dynamic 32 var dst []any 33 for i := range tpsrc[any]() { 34 dst[i] = tpsrc[any]()[i] 35 } 36 } 37 38 func tpfn2[T any]() { 39 type T2 struct { 40 b []T 41 } 42 43 var src []T 44 var dst T2 45 copy(dst.b, src) 46 } 47 48 func tpfn3[T any]() { 49 var src []T 50 var dst [][]T 51 copy(dst[0], src) 52 for i, v := range src { 53 // Don't flag, destination depends on loop variable 54 dst[i][i] = v 55 } 56 } 57 58 func tpfn4[T any]() { 59 var b []T 60 var a1 [5]T 61 var a2 [10]T 62 var a3 [5]T 63 64 copy(a1[:], b) 65 copy(b, a1[:]) 66 copy(a2[:], a1[:]) 67 a3 = a1 68 69 a1p := &a1 70 a2p := &a2 71 a3p := &a3 72 copy(a1p[:], b) 73 copy(b, a1p[:]) 74 copy(a2p[:], a1p[:]) 75 *a3p = *a1p 76 77 copy(a2p[:], a1[:]) 78 *a3p = a1 79 copy(a2[:], a1p[:]) 80 a3 = *a1p 81 } 82 83 func tpfn5[T any]() { 84 var src, dst []T 85 copy(dst, src) 86 87 len := func([]T) int { return 0 } 88 for i := 0; i < len(src); i++ { 89 dst[i] = src[i] 90 } 91 }