go/src/time
Daniel Martí 98409a44d5 cmd/vet: better align print warnings with fmt
fmt's %d, %x, and %X all accept pointer arguments. However, in cmd/vet's
printVerbs table, they were defined as if they did not accept pointer
arguments.

This inconsistency with fmt did not manifest to users since the vet
codebase worked around it. In particular, pointer arguments were usually
allowed for verbs that accepted integers, as the *types.Pointer argument
type case read the following:

	t&(argInt|argPointer) != 0

As a result, using the %q verb with a pointer resulted in a bug in
cmd/vet:

	$ go run f.go
	%!q(*int=0xc000014140)
	$ go vet f.go
	[no warning]

As documented, fmt's %q verb only accepts runes (integers), strings, and
byte slices. It should not accept pointers, and it does not. But since
vet mixed integers and pointers, it wasn't properly warning about the
misuse of fmt.

This patch surfaced another bug with fmt.Printf("%p", nil):

	$ go run f.go
	%!p(<nil>)
	$ go vet f.go
	[no warning]

As documented, fmt's %p verb only accepts pointers, and untyped nil is
not a valid pointer. But vet did not warn about it, which is another
inconsistency with fmt's documented rules. Fix that too, with a test,
also getting rid of the TODO associated with the code.

As a result of those changes, fix a wrong use of the fmt format verbs in
the standard library, now correctly spotted by vet.

Fixes #25233.

Change-Id: Id0ad31fbc25adfe1c46c6b6879b8d02b23633b3a
Reviewed-on: https://go-review.googlesource.com/111284
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-05-04 02:57:37 +00:00
..
example_test.go time: add example for FixedZone 2018-02-13 21:57:23 +00:00
export_android_test.go time: reduce OS dependent timezone related code 2017-09-27 14:14:45 +00:00
export_test.go time: enable Location loading from user provided timezone data 2017-11-21 19:13:52 +00:00
export_windows_test.go time: reduce OS dependent timezone related code 2017-09-27 14:14:45 +00:00
format.go all: remove some unused return parameters 2018-03-24 19:44:47 +00:00
format_test.go time: add support for parsing timezones denoted by sign and offset 2018-03-08 17:15:35 +00:00
genzabbrs.go all: use sort.Slice in a few more places 2017-09-22 12:39:14 +00:00
internal_test.go time: increase test coverage for Time.Sub 2018-04-16 21:14:40 +00:00
mono_test.go all: revert "all: prefer strings.LastIndexByte over strings.LastIndex" 2017-10-05 23:19:42 +00:00
sleep.go
sleep_test.go time: simplify comparison in test 2018-04-06 19:41:30 +00:00
sys_plan9.go time: unify three readFile implementations into one 2017-09-27 14:29:31 +00:00
sys_unix.go time: add wasm architecture 2018-04-13 21:12:31 +00:00
sys_windows.go time: unify three readFile implementations into one 2017-09-27 14:29:31 +00:00
tick.go
tick_test.go runtime: return deltimer early if timer.timersBucket is unset 2017-09-15 19:55:10 +00:00
time.go time: document that going to sleep may stop the monotonic clock 2018-04-13 00:50:22 +00:00
time_test.go time: increase test coverage for Time.Sub 2018-04-16 21:14:40 +00:00
zoneinfo.go all: remove some unused return parameters 2018-03-24 19:44:47 +00:00
zoneinfo_abbrs_windows.go go/printer, gofmt: tuned table alignment for better results 2018-04-04 13:39:34 -07:00
zoneinfo_android.go time: fix build on Android 2017-11-21 19:44:00 +00:00
zoneinfo_android_test.go
zoneinfo_ios.go time: reduce OS dependent timezone related code 2017-09-27 14:14:45 +00:00
zoneinfo_plan9.go time: reduce OS dependent timezone related code 2017-09-27 14:14:45 +00:00
zoneinfo_read.go time: enable Location loading from user provided timezone data 2017-11-21 19:13:52 +00:00
zoneinfo_test.go cmd/vet: better align print warnings with fmt 2018-05-04 02:57:37 +00:00
zoneinfo_unix.go time: add wasm architecture 2018-04-13 21:12:31 +00:00
zoneinfo_windows.go time: reduce OS dependent timezone related code 2017-09-27 14:14:45 +00:00
zoneinfo_windows_test.go time: reduce OS dependent timezone related code 2017-09-27 14:14:45 +00:00