This reverts commit 9bd1cc3fa1.
Reason for revert: New fixes in from upstream. Try this again.
Change-Id: Iea46f32857e8467f8d5a49b31e20a52fda8bce60
Reviewed-on: https://go-review.googlesource.com/37693
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Now that vet loads from source,
fmt can always be correctly resolved,
so the fmt.Formatter type is always available,
so we can reinstate the check.
Change-Id: I17f0c7fccf6960c9415de8774b15123135d57be8
Reviewed-on: https://go-review.googlesource.com/37692
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This simplifies the code and speeds it up.
It also allows us to eliminate some other TODOs;
those will come in a follow-up CL.
Running for the host platform, before:
real 0m9.907s
user 0m14.566s
sys 0m1.058s
After:
real 0m7.841s
user 0m12.339s
sys 0m0.572s
Running for a single non-host platform, before:
real 0m8.784s
user 0m15.451s
sys 0m3.445s
After:
real 0m7.681s
user 0m12.122s
sys 0m0.577s
Running for all platforms, before:
real 7m4.480s
user 8m43.398s
sys 1m15.683s
After:
real 4m37.596s
user 7m30.729s
sys 0m18.533s
It also makes my laptop considerably more
responsive while running for all platforms.
Change-Id: I748689fea0d2d4ef61aca2ce5524d03d8fafa5ca
Reviewed-on: https://go-review.googlesource.com/37691
Reviewed-by: Rob Pike <r@golang.org>
Add a -source flag to cmd/vet that instructs
it to typecheck purely from source code.
Updates #16086Fixes#19332
Change-Id: Ic83d0f14d5bb837a329d539b2873aeccdf7bf669
Reviewed-on: https://go-review.googlesource.com/37690
Reviewed-by: Rob Pike <r@golang.org>
Instead of constructing the importer in init, do it lazily as needed.
This lets us select the importer using a command line flag.
The addition of the command line flag will come in a follow-up CL.
Change-Id: Ieb3a5f01a34fb5bd220a95086daf5d6b37e83bb5
Reviewed-on: https://go-review.googlesource.com/37669
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This reverts commit 12b6c18139.
Reason for revert: Broke vet builder. #19322 was not fully fixed.
Change-Id: Id85131d4d0b8915480d65e3532da62b769463d70
Reviewed-on: https://go-review.googlesource.com/37625
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This is an inconsequential consequence of updating
math/big to use math/bits.
Better would be to teach the vet shift test
to size int/uint/uintptr to the platform in use,
eliminating the whole category of "might be too small".
Filed #19321 for that.
Change-Id: I7e0b837bd329132d7a564468c18502dd2e724fc6
Reviewed-on: https://go-review.googlesource.com/37576
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
When running on the host platform,
the standard library has almost certainly already been built.
However, all other platforms will probably need building.
Use the new -dolinkobj=false flag to cmd/compile
to only build the export data instead of doing a full compile.
Having partial object files could be confusing for people
doing subsequent cross-compiles, depending on what happens with #18369.
However, cmd/vet/all will mainly be run by builders
and core developers, who are probably fairly well-placed
to handle any such confusion.
This reduces the time on my machine for a cold run of
'go run main.go -all' by almost half:
benchmark old ns/op new ns/op delta
BenchmarkVetAll 240670814551 130784517074 -45.66%
Change-Id: Ieb866ffb2cb714b361b0a6104077652f8eacd166
Reviewed-on: https://go-review.googlesource.com/37385
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
A last-minute rollback of a change left some
unreachable code that we don't want to remove.
Change-Id: Ida0af5b18ed1a2e13ef66c303694afcc49d7bff4
Reviewed-on: https://go-review.googlesource.com/37304
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
cmd/vet has a known deficiency in its handling of fmt.Formatters.
This causes a spurious printf error only for non-host platforms.
Since cmd/vet/all may get run on any given platform,
whitelists cannot help here.
Work around the issue by skipping printf tests entirely
for non-host platforms.
Work around the one known acceptable false positive from vet
by whitelisting the file that contains it.
Change-Id: Id74b3d4db0519cf9a670a065683715f856266e45
Reviewed-on: https://go-review.googlesource.com/36936
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Given
var t struct{ lock sync.Mutex }
var fntab []func(t)
f(a(), b(&t), c(), fntab[0](t))
Before:
function call copies lock value: struct{lock sync.Mutex} contains sync.Mutex
After:
call of fntab[0] copies lock value: struct{lock sync.Mutex} contains sync.Mutex
This will make diagnosis easier when there are multiple function calls per line.
Change-Id: I9881713c5671b847b84a0df0115f57e7cba17d72
Reviewed-on: https://go-review.googlesource.com/34730
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This CL also re-enables the cgo tests that were accidentally disabled
in CL 32754.
Fixes#18389.
Change-Id: I2fdc4fe3ec1f92b7da3db3fa66f4e0f806fc899f
Reviewed-on: https://go-review.googlesource.com/34660
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The check for duplicate struct field tags introduced in CL 16704
triggers a panic when an anonymous struct field with a duplicate name
is encountered. For such a field, the names slice of the ast.Field is
nil but accessed regardless to generate the warning message.
Additionally, the check produces false positives for XML tags in some
cases:
- When fields are encoded as XML attributes, a warning is produced when
an attribute reuses a name previously used for an element.
Example:
type Foo struct {
First int `xml:"a"`
NoDup int `xml:"a,attr"` // warning about reuse of "a"
}
- When XMLName is used to set the name of the enclosing struct element,
it is treated as a regular struct field.
Example:
type Bar struct {
XMLName xml.Name `xml:"a"`
NoDup int `xml:"a"` // warning about reuse of "a"
}
This commit addresses all three issues. The panic is avoided by using
the type name instead of the field name for anonymous struct fields when
generating the warning message. An additional namespace for checking XML
attribute names separately from element names is introduced. Lastly,
fields named XMLName are excluded from the check for duplicate tags.
Updates #18256
Change-Id: Ida48ea8584b56bd4d12ae3ebd588a66ced2594cc
Reviewed-on: https://go-review.googlesource.com/34070
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
These don't use any flags in TestMain itself, so the call is redundant
as M.Run will do it.
Change-Id: I00f2ac7f846dc2c3ad3535eb8177616b2d900149
Reviewed-on: https://go-review.googlesource.com/33275
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
cmd/vet/all still doesn't run for mips/mipsle,
because the rest of the toolchain doesn't yet
fully support it.
Change-Id: I1a86b0edddbdcd5f43e752208508d99da7aabbb3
Reviewed-on: https://go-review.googlesource.com/33134
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
This check detects the code
resp, err := http.Get("http://foo.com")
defer resp.Body.Close()
if err != nil {
...
}
For every call to a function on the net/http package or any method
on http.Client that returns (*http.Response, error), it checks
whether the next line is a defer statement that calls on the response.
Fixes#17780.
Change-Id: I9d70edcbfa2bad205bf7f45281597d074c795977
Reviewed-on: https://go-review.googlesource.com/32911
Reviewed-by: Rob Pike <r@golang.org>
Was 2.3 seconds. Now 1.4 seconds.
Next win would be not running a child process and refactoring main so
it could be called from tests easily. But that would also require
rewriting the errchk written in Perl. This appears to be the last user
of errchk in the tree.
Updates #17751
Change-Id: Id7c3cec76f438590789b994e756f55b5397be07f
Reviewed-on: https://go-review.googlesource.com/32754
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
This reverts commit aa8c8e770e.
Reason: Decision to back out current alias implementation.
For #16339.
Change-Id: I4db9a8d6b3625c794be9d2f1ff0e9c047f383d28
Reviewed-on: https://go-review.googlesource.com/32827
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Chris Manghane <cmang@golang.org>
Some of these whitelist entries could be
eliminated, e.g. by the addition of Go
declarations, but this is a start.
Change-Id: I2fb3234cf05ebc6b161aacac2d4c15d810d50527
Reviewed-on: https://go-review.googlesource.com/32671
Reviewed-by: Michael Munday <munday@ca.ibm.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Adapted from the mips64 test case.
Fixes#17745.
Change-Id: I46f0900028adb936dcab2cdc701ea11d0a3cb95e
Reviewed-on: https://go-review.googlesource.com/32611
Run-TryBot: Michael Munday <munday@ca.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Rob Pike <r@golang.org>
This is not strictly illegal but it probably should be (too late)
and doesn't mean what it looks like it means:
the second key-value pair has the key ",xml".
Fixes#14466.
Change-Id: I174bccc23fd28affeb87f57f77c6591634ade641
Reviewed-on: https://go-review.googlesource.com/32031
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Quentin Smith <quentin@golang.org>
It no longer exists as of CL 31010.
Change-Id: Idd61f392544cad8b3f3f8d984dc5c953b473e2e5
Reviewed-on: https://go-review.googlesource.com/31934
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This will cause godoc to correctly render these docs,
since go/doc.ToHTML requires no punctuation for headings.
Change-Id: Ic95245147d3585f2ccc59d4424fcab17d2a5617b
Reviewed-on: https://go-review.googlesource.com/31319
Reviewed-by: Rob Pike <r@golang.org>
It is easy to make the mistake of duplicating json struct field
tags especially when copy/pasting. This commit causes go vet to
report the mistake. Only field tags in the same struct type are
considered, because that is the only case which is undoubtedly an
error.
Fixes#12791.
Change-Id: I4130e4c04b177694cc0daf8f1acaf0751d4f062b
Reviewed-on: https://go-review.googlesource.com/16704
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Example on linux_amd64 for 'go tool vet -h':
Before:
Usage of /usr/local/go/pkg/tool/linux_amd64/vet:
After:
Usage of vet:
Change-Id: I11cb16b656bd097062d57a8c7441fbe66caaef78
Reviewed-on: https://go-review.googlesource.com/29294
Reviewed-by: Rob Pike <r@golang.org>
Was missing a title in the documentation, so it formatted wrong.
Fixes#17124
Change-Id: Ie8a9c36fbc54eed7d8a761f89a088e582b8c062d
Reviewed-on: https://go-review.googlesource.com/29340
Reviewed-by: Andrew Gerrand <adg@golang.org>
This is a temporary measure to work around #17057.
It will be reverted when #17057 is fixed.
Change-Id: I21c02f63f3530774c91065cfed5d9c566839ed9f
Reviewed-on: https://go-review.googlesource.com/28959
Reviewed-by: Rob Pike <r@golang.org>