github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/unused/testdata/src/example.com/fields/fields.go (about) 1 // Test of field usage detection 2 3 package pkg 4 5 type t1 struct { //@ used("t1", true) 6 f11 int //@ used("f11", true) 7 f12 int //@ used("f12", true) 8 } 9 type t2 struct { //@ used("t2", true) 10 f21 int //@ used("f21", true) 11 f22 int //@ used("f22", true) 12 } 13 type t3 struct { //@ used("t3", true) 14 f31 t4 //@ used("f31", true) 15 } 16 type t4 struct { //@ used("t4", true) 17 f41 int //@ used("f41", true) 18 } 19 type t5 struct { //@ used("t5", true) 20 f51 int //@ used("f51", true) 21 } 22 type t6 struct { //@ used("t6", true) 23 f61 int //@ used("f61", true) 24 } 25 type t7 struct { //@ used("t7", true) 26 f71 int //@ used("f71", true) 27 } 28 type m1 map[string]t7 //@ used("m1", true) 29 type t8 struct { //@ used("t8", true) 30 f81 int //@ used("f81", true) 31 } 32 type t9 struct { //@ used("t9", true) 33 f91 int //@ used("f91", true) 34 } 35 type t10 struct { //@ used("t10", true) 36 f101 int //@ used("f101", true) 37 } 38 type t11 struct { //@ used("t11", true) 39 f111 int //@ used("f111", true) 40 } 41 type s1 []t11 //@ used("s1", true) 42 type t12 struct { //@ used("t12", true) 43 f121 int //@ used("f121", true) 44 } 45 type s2 []t12 //@ used("s2", true) 46 type t13 struct { //@ used("t13", true) 47 f131 int //@ used("f131", true) 48 } 49 type t14 struct { //@ used("t14", true) 50 f141 int //@ used("f141", true) 51 } 52 type a1 [1]t14 //@ used("a1", true) 53 type t15 struct { //@ used("t15", true) 54 f151 int //@ used("f151", true) 55 } 56 type a2 [1]t15 //@ used("a2", true) 57 type t16 struct { //@ used("t16", true) 58 f161 int //@ used("f161", true) 59 } 60 type t17 struct { //@ used("t17", false) 61 f171 int //@ quiet("f171") 62 f172 int //@ quiet("f172") 63 } 64 type t18 struct { //@ used("t18", true) 65 f181 int //@ used("f181", true) 66 f182 int //@ used("f182", false) 67 f183 int //@ used("f183", false) 68 } 69 70 type t19 struct { //@ used("t19", true) 71 f191 int //@ used("f191", true) 72 } 73 type m2 map[string]t19 //@ used("m2", true) 74 75 type t20 struct { //@ used("t20", true) 76 f201 int //@ used("f201", true) 77 } 78 type m3 map[string]t20 //@ used("m3", true) 79 80 type t21 struct { //@ used("t21", true) 81 f211 int //@ used("f211", false) 82 f212 int //@ used("f212", true) 83 } 84 type t22 struct { //@ used("t22", false) 85 f221 int //@ quiet("f221") 86 f222 int //@ quiet("f222") 87 } 88 89 func foo() { //@ used("foo", true) 90 _ = t10{1} 91 _ = t21{f212: 1} 92 _ = []t1{{1, 2}} 93 _ = t2{1, 2} 94 _ = []struct { 95 a int //@ used("a", true) 96 }{{1}} 97 98 // XXX 99 // _ = []struct{ foo struct{ bar int } }{{struct{ bar int }{1}}} 100 101 _ = []t1{t1{1, 2}} 102 _ = []t3{{t4{1}}} 103 _ = map[string]t5{"a": {1}} 104 _ = map[t6]string{{1}: "a"} 105 _ = m1{"a": {1}} 106 _ = map[t8]t8{{}: {1}} 107 _ = map[t9]t9{{1}: {}} 108 _ = s1{{1}} 109 _ = s2{2: {1}} 110 _ = [...]t13{{1}} 111 _ = a1{{1}} 112 _ = a2{0: {1}} 113 _ = map[[1]t16]int{{{1}}: 1} 114 y := struct { //@ used("y", true) 115 x int //@ used("x", true) 116 }{} 117 _ = y 118 _ = t18{f181: 1} 119 _ = []m2{{"a": {1}}} 120 _ = [][]m3{{{"a": {1}}}} 121 } 122 123 func init() { foo() } //@ used("init", true) 124 125 func superUnused() { //@ used("superUnused", false) 126 var _ struct { //@ quiet("_") 127 x int //@ quiet("x") 128 } 129 }