golang.org/x/tools@v0.21.0/internal/refactor/inline/testdata/empty-body.txtar (about) 1 Test of elimination of calls to functions with completely empty bodies. 2 The arguments must still be evaluated and their results discarded. 3 The number of discard blanks must match the type, not the syntax (see 2-ary f). 4 If there are no arguments, the entire call is eliminated. 5 6 We cannot eliminate some pure argument expressions because they 7 may contain the last reference to a local variable. 8 9 -- go.mod -- 10 module testdata 11 go 1.12 12 13 -- a/a0.go -- 14 package a 15 16 func _() { 17 empty() //@ inline(re"empty", empty0) 18 } 19 20 func empty(...any) {} 21 22 -- empty0 -- 23 package a 24 25 func _() { 26 //@ inline(re"empty", empty0) 27 } 28 29 func empty(...any) {} 30 31 -- a/a1.go -- 32 package a 33 34 func _(ch chan int) { 35 empty(f()) //@ inline(re"empty", empty1) 36 } 37 38 func f() (int, int) 39 40 -- empty1 -- 41 package a 42 43 func _(ch chan int) { 44 _, _ = f() //@ inline(re"empty", empty1) 45 } 46 47 func f() (int, int) 48 49 -- a/a2.go -- 50 package a 51 52 func _(ch chan int) { 53 empty(-1, ch, len(""), g(), <-ch) //@ inline(re"empty", empty2) 54 } 55 56 func g() int 57 58 -- empty2 -- 59 package a 60 61 func _(ch chan int) { 62 _ = []any{-1, ch, len(""), g(), <-ch} //@ inline(re"empty", empty2) 63 } 64 65 func g() int 66 67 -- a/a3.go -- 68 package a 69 70 func _() { 71 new(T).empty() //@ inline(re"empty", empty3) 72 } 73 74 type T int 75 76 func (T) empty() int {} 77 78 -- empty3 -- 79 package a 80 81 func _() { 82 //@ inline(re"empty", empty3) 83 } 84 85 type T int 86 87 func (T) empty() int {} 88 89 -- a/a4.go -- 90 package a 91 92 func _() { 93 var x T 94 x.empty() //@ inline(re"empty", empty4) 95 } 96 97 -- empty4 -- 98 package a 99 100 func _() { 101 var x T 102 _ = x //@ inline(re"empty", empty4) 103 }