From 459cd35ec092fdb48e1825ccd01fb630a77474bf Mon Sep 17 00:00:00 2001 From: cui fliter Date: Sat, 7 Oct 2023 16:13:04 +0800 Subject: [PATCH] doc/go1.22: mention new #vet analyzer Change-Id: Ib135101bc8adbdb158c5e98bcca14e13d7ac963b Reviewed-on: https://go-review.googlesource.com/c/go/+/533555 TryBot-Result: Gopher Robot Reviewed-by: Alan Donovan LUCI-TryBot-Result: Go LUCI Run-TryBot: Tim King Reviewed-by: Tim King --- doc/go1.22.html | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/doc/go1.22.html b/doc/go1.22.html index d7e8bbd7fb..2950a5b085 100644 --- a/doc/go1.22.html +++ b/doc/go1.22.html @@ -116,6 +116,47 @@ packages that do not have their own test files. Prior to Go 1.22 a

+

Vet

+ +

New warnings for missing values after append

+ +

+ The vet tool now reports calls to + append that pass + no values to be appended to the slice, such as slice = append(slice). + Such a statement has no effect, and experience has shown that is nearly always a mistake. +

+ +

New warnings for deferring time.Since

+ +

+ The vet tool now reports a non-deferred call to + time.Since(t) within a defer statement. + This is equivalent to calling time.Now().Sub(t) before the defer statement, + not when the deferred function is called. In nearly all cases, the correct code + requires deferring the time.Since call. For example: +

+ +
+t := time.Now()
+defer log.Println(time.Since(t)) // non-deferred call to time.Since
+tmp := time.Since(t); defer log.Println(tmp) // equivalent to the previous defer
+
+defer func() {
+  log.Println(time.Since(t)) // a correctly deferred call to time.Since
+}()
+
+ +

New warnings for mismatched key-value pairs in log/slog calls

+ +

+ The vet tool now reports invalid arguments in calls to functions and methods + in the structured logging package, log/slog, + that accept alternating key/value pairs. + It reports calls where an argument in a key position is neither a + string nor a slog.Attr, and where a final key is missing its value. +

+

Runtime

-- 2.48.1