From: Russ Cox Date: Fri, 2 Dec 2011 19:12:53 +0000 (-0500) Subject: spec: additional composite literal shortenings per Go 1 plan X-Git-Tag: weekly.2011-12-06~39 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5f49456465f53f96bee03ac8cbe0d564e31576c2;p=gostls13.git spec: additional composite literal shortenings per Go 1 plan R=golang-dev, gri, r, r CC=golang-dev https://golang.org/cl/5449067 --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 00cb962872..04cab1dbb6 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -2118,11 +2118,26 @@ tmp[0 : n] Within a composite literal of array, slice, or map type T, elements that are themselves composite literals may elide the respective literal type if it is identical to the element type of T. +Similarly, elements that are addresses of composite literals may elide +the &T when the the element type is *T. +The same elisions may be applied to field values within a struct literal, +but only if the value has a field name key.

+ +
-[...]Point{{1.5, -3.5}, {0, 0}}  // same as [...]Point{Point{1.5, -3.5}, Point{0, 0}}
-[][]int{{1, 2, 3}, {4, 5}}       // same as [][]int{[]int{1, 2, 3}, []int{4, 5}}
+[...]Point{{1.5, -3.5}, {0, 0}}   // same as [...]Point{Point{1.5, -3.5}, Point{0, 0}}
+[][]int{{1, 2, 3}, {4, 5}}        // same as [][]int{[]int{1, 2, 3}, []int{4, 5}}
+
+[...]*Point{{1.5, -3.5}, {0, 0}}  // same as [...]*Point{&Point{1.5, -3.5}, &Point{0, 0}}
+
+type List struct {
+	Val int
+	Next *List
+}
+
+&List{Val: 1, Next: {Val: 2}}     // same as &List{Val: 1, Next: &List{Val: 2}}