未命名指针返回值的预期标识符

gofmt gives an "expected identifier" warning about this function signature at this point:

func foo() (*int, y int) {}
            ^

However, it does not complain about this signature:

func foo() (int, y int) {}

How can I name one return value without having gofmt complain about the unnamed pointer return value?

How can I name one return value without having gofmt complain about the unnamed pointer return value?


The Go Programming Language Specification

Blank identifier

The blank identifier is represented by the underscore character _. It serves as an anonymous placeholder instead of a regular (non-blank) identifier and has special meaning in declarations, as an operand, and in assignments.


Use the blank identifier (_). For example,

package main

func foo() (_ *int, y int) { return nil, 0 }

func main() {}

Playground: https://play.golang.org/p/RBfxkDaZdOB