Skip to content

Commit 2ac1ca9

Browse files
Xiangdong JiJay Conrod
Xiangdong Ji
authored and
Jay Conrod
committed
cmd/vet: honor analyzer flags when running vet outside $GOROOT/src
Additional vet flags specified by user are discarded if 'go vet' is invoked outside $GOROOT/src to check a package under $GOROOT (including those under "vendor" of $GOROOT), fix it by avoiding the overwriting, the logic of detemining if the package under vetting comes from $GOROOT remains untouched. Also checked 'go tool vet <options> <cfg>' and 'go vet <options> <user pkg>', both worked w./w.o this fix. Fixes #35837. Change-Id: I549af7964e40440afd35f2d1971f77eee6f8de34 Reviewed-on: https://go-review.googlesource.com/c/go/+/209498 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
1 parent 386b1a4 commit 2ac1ca9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/cmd/go/internal/work/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ func (b *Builder) vet(a *Action) error {
10361036
// There's too much unsafe.Pointer code
10371037
// that vet doesn't like in low-level packages
10381038
// like runtime, sync, and reflect.
1039-
vetFlags = []string{"-unsafeptr=false"}
1039+
vetFlags = append(vetFlags, string("-unsafeptr=false"))
10401040
}
10411041

10421042
// Note: We could decide that vet should compute export data for
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
env GO111MODULE=off
2+
3+
# Issue 35837. Verify that "go vet -<analyzer> <std package>" works if 'pwd' is not $GOROOT/src
4+
# we utilize the package runtime/testdata/testprog as the issue is specific to vetting standard package
5+
6+
go vet -n -unreachable=false runtime/testdata/testprog
7+
stderr '-unreachable=false'
8+
stderr '-unsafeptr=false'

0 commit comments

Comments
 (0)