github.com/miolini/go@v0.0.0-20160405192216-fca68c8cb408/src/cmd/vet/testdata/copylock.go (about)

     1  package testdata
     2  
     3  import "sync"
     4  
     5  func OkFunc() {
     6  	var x *sync.Mutex
     7  	p := x
     8  	var y sync.Mutex
     9  	p = &y
    10  
    11  	var z = sync.Mutex{}
    12  	w := sync.Mutex{}
    13  
    14  	w = sync.Mutex{}
    15  	q := struct{ L sync.Mutex }{
    16  		L: sync.Mutex{},
    17  	}
    18  
    19  	yy := []Tlock{
    20  		Tlock{},
    21  		Tlock{
    22  			once: sync.Once{},
    23  		},
    24  	}
    25  
    26  	nl := new(sync.Mutex)
    27  	mx := make([]sync.Mutex, 10)
    28  	xx := struct{ L *sync.Mutex }{
    29  		L: new(sync.Mutex),
    30  	}
    31  }
    32  
    33  type Tlock struct {
    34  	once sync.Once
    35  }
    36  
    37  func BadFunc() {
    38  	var x *sync.Mutex
    39  	p := x
    40  	var y sync.Mutex
    41  	p = &y
    42  	*p = *x // ERROR "assignment copies lock value to \*p: sync.Mutex"
    43  
    44  	var t Tlock
    45  	var tp *Tlock
    46  	tp = &t
    47  	*tp = t // ERROR "assignment copies lock value to \*tp: testdata.Tlock contains sync.Once contains sync.Mutex"
    48  	t = *tp // ERROR "assignment copies lock value to t: testdata.Tlock contains sync.Once contains sync.Mutex"
    49  
    50  	y := *x   // ERROR "assignment copies lock value to y: sync.Mutex"
    51  	var z = t // ERROR "variable declaration copies lock value to z: testdata.Tlock contains sync.Once contains sync.Mutex"
    52  
    53  	w := struct{ L sync.Mutex }{
    54  		L: *x, // ERROR "literal copies lock value from \*x: sync.Mutex"
    55  	}
    56  	var q = map[int]Tlock{
    57  		1: t,   // ERROR "literal copies lock value from t: testdata.Tlock contains sync.Once contains sync.Mutex"
    58  		2: *tp, // ERROR "literal copies lock value from \*tp: testdata.Tlock contains sync.Once contains sync.Mutex"
    59  	}
    60  	yy := []Tlock{
    61  		t,   // ERROR "literal copies lock value from t: testdata.Tlock contains sync.Once contains sync.Mutex"
    62  		*tp, // ERROR "literal copies lock value from \*tp: testdata.Tlock contains sync.Once contains sync.Mutex"
    63  	}
    64  
    65  	// override 'new' keyword
    66  	new := func(interface{}) {}
    67  	new(t) // ERROR "function call copies lock value: testdata.Tlock contains sync.Once contains sync.Mutex"
    68  }