github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/unused/testdata/src/example.com/conversion/conversion.go (about) 1 package pkg 2 3 import ( 4 "compress/flate" 5 "unsafe" 6 ) 7 8 type t1 struct { //@ used("t1", true) 9 a int //@ used("a", true) 10 b int //@ used("b", true) 11 } 12 13 type t2 struct { //@ used("t2", true) 14 a int //@ used("a", true) 15 b int //@ used("b", true) 16 } 17 18 type t3 struct { //@ used("t3", true) 19 a int //@ used("a", true) 20 b int //@ used("b", false) 21 } 22 23 type t4 struct { //@ used("t4", true) 24 a int //@ used("a", true) 25 b int //@ used("b", false) 26 } 27 28 type t5 struct { //@ used("t5", true) 29 a int //@ used("a", true) 30 b int //@ used("b", true) 31 } 32 33 type t6 struct { //@ used("t6", true) 34 a int //@ used("a", true) 35 b int //@ used("b", true) 36 } 37 38 type t7 struct { //@ used("t7", true) 39 a int //@ used("a", true) 40 b int //@ used("b", true) 41 } 42 43 type t8 struct { //@ used("t8", true) 44 a int //@ used("a", true) 45 b int //@ used("b", true) 46 } 47 48 type t9 struct { //@ used("t9", true) 49 Offset int64 //@ used("Offset", true) 50 Err error //@ used("Err", true) 51 } 52 53 type t10 struct { //@ used("t10", true) 54 a int //@ used("a", true) 55 b int //@ used("b", true) 56 } 57 58 func fn() { //@ used("fn", true) 59 // All fields in t2 used because they're initialised in t1 60 v1 := t1{0, 1} //@ used("v1", true) 61 v2 := t2(v1) //@ used("v2", true) 62 _ = v2 63 64 // Field b isn't used by anyone 65 v3 := t3{} //@ used("v3", true) 66 v4 := t4(v3) //@ used("v4", true) 67 println(v3.a) 68 _ = v4 69 70 // Both fields are used 71 v5 := t5{} //@ used("v5", true) 72 v6 := t6(v5) //@ used("v6", true) 73 println(v5.a) 74 println(v6.b) 75 76 v7 := &t7{} //@ used("v7", true) 77 println(v7.a) 78 println(v7.b) 79 v8 := (*t8)(v7) //@ used("v8", true) 80 _ = v8 81 82 vb := flate.ReadError{} //@ used("vb", true) 83 v9 := t9(vb) //@ used("v9", true) 84 _ = v9 85 86 // All fields are used because this is an unsafe conversion 87 var b []byte //@ used("b", true) 88 v10 := (*t10)(unsafe.Pointer(&b[0])) //@ used("v10", true) 89 _ = v10 90 } 91 92 func init() { fn() } //@ used("init", true)