diff options
author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2020-09-09 11:09:01 +0700 |
---|---|---|
committer | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2020-09-12 08:31:49 +0000 |
commit | 2c95e3a6a8377ca9c72608c25b4cf2506baf782f (patch) | |
tree | e8696bf16d352c026cf84e0cab63c53369f67fe8 /test/escape_indir.go | |
parent | d7384f36121d52191097af50d6dc12c0eb08fd75 (diff) | |
download | go-2c95e3a6a8377ca9c72608c25b4cf2506baf782f.tar.gz go-2c95e3a6a8377ca9c72608c25b4cf2506baf782f.zip |
cmd/compile: use clearer error message for stuct literal
This CL changes "T literal.M" error message to "T{...}.M". It's clearer
expression and focusing user on actual issue.
Updates #38745
Change-Id: I84b455a86742f37e0bde5bf390aa02984eecc3c9
Reviewed-on: https://go-review.googlesource.com/c/go/+/253677
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test/escape_indir.go')
-rw-r--r-- | test/escape_indir.go | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/test/escape_indir.go b/test/escape_indir.go index 19889f259f..12005e35f9 100644 --- a/test/escape_indir.go +++ b/test/escape_indir.go @@ -23,7 +23,7 @@ type ConstPtr2 struct { func constptr0() { i := 0 // ERROR "moved to heap: i" - x := &ConstPtr{} // ERROR "&ConstPtr literal does not escape" + x := &ConstPtr{} // ERROR "&ConstPtr{} does not escape" // BAD: i should not escape here x.p = &i _ = x @@ -31,55 +31,55 @@ func constptr0() { func constptr01() *ConstPtr { i := 0 // ERROR "moved to heap: i" - x := &ConstPtr{} // ERROR "&ConstPtr literal escapes to heap" + x := &ConstPtr{} // ERROR "&ConstPtr{} escapes to heap" x.p = &i return x } func constptr02() ConstPtr { i := 0 // ERROR "moved to heap: i" - x := &ConstPtr{} // ERROR "&ConstPtr literal does not escape" + x := &ConstPtr{} // ERROR "&ConstPtr{} does not escape" x.p = &i return *x } func constptr03() **ConstPtr { i := 0 // ERROR "moved to heap: i" - x := &ConstPtr{} // ERROR "&ConstPtr literal escapes to heap" "moved to heap: x" + x := &ConstPtr{} // ERROR "&ConstPtr{} escapes to heap" "moved to heap: x" x.p = &i return &x } func constptr1() { i := 0 // ERROR "moved to heap: i" - x := &ConstPtr{} // ERROR "&ConstPtr literal escapes to heap" + x := &ConstPtr{} // ERROR "&ConstPtr{} escapes to heap" x.p = &i sink = x } func constptr2() { i := 0 // ERROR "moved to heap: i" - x := &ConstPtr{} // ERROR "&ConstPtr literal does not escape" + x := &ConstPtr{} // ERROR "&ConstPtr{} does not escape" x.p = &i - sink = *x // ERROR "\*x escapes to heap" + sink = *x // ERROR "\*x escapes to heap" } func constptr4() *ConstPtr { p := new(ConstPtr) // ERROR "new\(ConstPtr\) escapes to heap" - *p = *&ConstPtr{} // ERROR "&ConstPtr literal does not escape" + *p = *&ConstPtr{} // ERROR "&ConstPtr{} does not escape" return p } func constptr5() *ConstPtr { p := new(ConstPtr) // ERROR "new\(ConstPtr\) escapes to heap" - p1 := &ConstPtr{} // ERROR "&ConstPtr literal does not escape" + p1 := &ConstPtr{} // ERROR "&ConstPtr{} does not escape" *p = *p1 return p } // BAD: p should not escape here func constptr6(p *ConstPtr) { // ERROR "leaking param content: p" - p1 := &ConstPtr{} // ERROR "&ConstPtr literal does not escape" + p1 := &ConstPtr{} // ERROR "&ConstPtr{} does not escape" *p1 = *p _ = p1 } @@ -102,17 +102,17 @@ func constptr8() *ConstPtr { func constptr9() ConstPtr { p := new(ConstPtr) // ERROR "new\(ConstPtr\) does not escape" var p1 ConstPtr2 - i := 0 // ERROR "moved to heap: i" + i := 0 // ERROR "moved to heap: i" p1.p = &i p.c = p1 return *p } func constptr10() ConstPtr { - x := &ConstPtr{} // ERROR "moved to heap: x" "&ConstPtr literal escapes to heap" + x := &ConstPtr{} // ERROR "moved to heap: x" "&ConstPtr{} escapes to heap" i := 0 // ERROR "moved to heap: i" var p *ConstPtr - p = &ConstPtr{p: &i, x: &x} // ERROR "&ConstPtr literal does not escape" + p = &ConstPtr{p: &i, x: &x} // ERROR "&ConstPtr{...} does not escape" var pp **ConstPtr pp = &p return **pp @@ -121,7 +121,7 @@ func constptr10() ConstPtr { func constptr11() *ConstPtr { i := 0 // ERROR "moved to heap: i" p := new(ConstPtr) // ERROR "new\(ConstPtr\) escapes to heap" - p1 := &ConstPtr{} // ERROR "&ConstPtr literal does not escape" + p1 := &ConstPtr{} // ERROR "&ConstPtr{} does not escape" p1.p = &i *p = *p1 return p @@ -134,7 +134,7 @@ func foo(p **int) { // ERROR "p does not escape" } func foo1(p *int) { // ERROR "p does not escape" - i := 0 // ERROR "moved to heap: i" + i := 0 // ERROR "moved to heap: i" y := &p *y = &i } @@ -148,13 +148,13 @@ func foo2() { var z Z z.f = &x p := z.f - i := 0 // ERROR "moved to heap: i" + i := 0 // ERROR "moved to heap: i" *p = &i } var global *byte func f() { - var x byte // ERROR "moved to heap: x" + var x byte // ERROR "moved to heap: x" global = &*&x } |