]> Cypherpunks repositories - gostls13.git/commitdiff
gofmt: explain why lower bounds aren't automatically simplified
authorRobert Hencke <robert.hencke@gmail.com>
Thu, 3 Oct 2013 17:55:17 +0000 (10:55 -0700)
committerRob Pike <r@golang.org>
Thu, 3 Oct 2013 17:55:17 +0000 (10:55 -0700)
Full credit goes to gri and rsc for their explanations.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14229043

src/cmd/gofmt/simplify.go

index e9a67a73ac7ae4673b4880185f0b068f936b1d7a..45d000d675e8cdbccf155d4351765b20698cc1ff 100644 (file)
@@ -90,6 +90,10 @@ func (s *simplifier) Visit(node ast.Node) ast.Visitor {
                // Note: We could also simplify slice expressions of the form s[0:b] to s[:b]
                //       but we leave them as is since sometimes we want to be very explicit
                //       about the lower bound.
+               // An example where the 0 helps:
+               //       x, y, z := b[0:2], b[2:4], b[4:6]
+               // An example where it does not:
+               //       x, y := b[:n], b[n:]
 
        case *ast.RangeStmt:
                // a range of the form: for x, _ = range v {...}