1// errorcheck -0 -l -m 2 3// Copyright 2019 The Go Authors. All rights reserved. 4// Use of this source code is governed by a BSD-style 5// license that can be found in the LICENSE file. 6 7package p 8 9var sink interface{} 10 11func f1() { 12 var t T 13 f := t.noescape // ERROR "t.noescape does not escape" 14 f() 15} 16 17func f2() { 18 var t T // ERROR "moved to heap" 19 f := t.escape // ERROR "t.escape does not escape" 20 f() 21} 22 23func f3() { 24 var t T // ERROR "moved to heap" 25 f := t.returns // ERROR "t.returns does not escape" 26 sink = f() 27} 28 29type T struct{} 30 31func (t *T) noescape() {} // ERROR "t does not escape" 32func (t *T) escape() { sink = t } // ERROR "leaking param: t$" 33func (t *T) returns() *T { return t } // ERROR "leaking param: t to result ~r0 level=0" 34 35func (t *T) recursive() { // ERROR "leaking param: t$" 36 sink = t 37 38 var t2 T // ERROR "moved to heap" 39 f := t2.recursive // ERROR "t2.recursive does not escape" 40 f() 41} 42