cmd/vet: allow untyped composite literals to be unkeyed

We can trust that untyped composite literals are part of a slice literal
and not emit a vet warning for those.

Fixes #9171

Change-Id: Ia7c081e543b850f8be1fd1f9e711520061e70bed
Reviewed-on: https://go-review.googlesource.com/22000
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
diff --git a/src/cmd/vet/composite.go b/src/cmd/vet/composite.go
index 731c793..ac6a598 100644
--- a/src/cmd/vet/composite.go
+++ b/src/cmd/vet/composite.go
@@ -68,8 +68,10 @@
 	allKeyValue := true
 	for _, e := range c.Elts {
 		if _, ok := e.(*ast.KeyValueExpr); !ok {
-			allKeyValue = false
-			break
+			if cl, ok := e.(*ast.CompositeLit); !ok || cl.Type != nil {
+				allKeyValue = false
+				break
+			}
 		}
 	}
 	if allKeyValue {
diff --git a/src/cmd/vet/testdata/composite.go b/src/cmd/vet/testdata/composite.go
index 69e7d7c..0355c0b 100644
--- a/src/cmd/vet/testdata/composite.go
+++ b/src/cmd/vet/testdata/composite.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// This file contains tests for the untagged struct literal checker.
-
 // This file contains the test for untagged struct literals.
 
 package testdata
@@ -11,6 +9,7 @@
 import (
 	"flag"
 	"go/scanner"
+	"unicode"
 )
 
 var Okay1 = []string{
@@ -57,6 +56,11 @@
 	"DefValue",
 }
 
+// SpecialCase is an (aptly named) slice of CaseRange to test issue 9171.
+var GoodNamedSliceLiteralUsedInTests = unicode.SpecialCase{
+	{Lo: 1, Hi: 2},
+}
+
 // Used to test the check for slices and arrays: If that test is disabled and
 // vet is run with --compositewhitelist=false, this line triggers an error.
 // Clumsy but sufficient.