github.com/golangci/go-tools@v0.0.0-20190318060251-af6baa5dc196/unused/testdata/src/conversion/conversion.go (about)

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