mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
This information is redundant with the position information already
provided. Also, no other -m diagnostics print out function name.
While here, report parameter leak diagnostics against the parameter
declaration position rather than the function, and use Warnl for
"moved to heap" messages.
Test cases updated programmatically by removing the first word from
every "no match for" error emitted by run.go:
go run run.go |& \
sed -E -n 's/^(.*):(.*): no match for `([^ ]* (.*))` in:$/\1!\2!\3!\4/p' | \
while IFS='!' read -r fn line before after; do
before=$(echo "$before" | sed 's/[.[\*^$()+?{|]/\\&/g')
after=$(echo "$after" | sed -E 's/(\&|\\)/\\&/g')
fn=$(find . -name "${fn}" | head -1)
sed -i -E -e "${line}s/\"${before}\"/\"${after}\"/" "${fn}"
done
Passes toolstash-check.
Change-Id: I6e02486b1409e4a8dbb2b9b816d22095835426b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/195040
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
37 lines
771 B
Go
37 lines
771 B
Go
// errorcheck -0 -l -m
|
|
|
|
// Copyright 2017 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Issue 21709: range expression overly escapes.
|
|
|
|
package p
|
|
|
|
type S struct{}
|
|
|
|
func (s *S) Inc() {} // ERROR "s does not escape"
|
|
var N int
|
|
|
|
func F1() {
|
|
var s S // ERROR "moved to heap: s"
|
|
for i := 0; i < N; i++ {
|
|
fs := []func(){ // ERROR "\[\]func\(\) literal does not escape"
|
|
s.Inc, // ERROR "s.Inc does not escape"
|
|
}
|
|
for _, f := range fs {
|
|
f()
|
|
}
|
|
}
|
|
}
|
|
|
|
func F2() {
|
|
var s S // ERROR "moved to heap: s"
|
|
for i := 0; i < N; i++ {
|
|
for _, f := range []func(){ // ERROR "\[\]func\(\) literal does not escape"
|
|
s.Inc, // ERROR "s.Inc does not escape"
|
|
} {
|
|
f()
|
|
}
|
|
}
|
|
}
|