cmd/protoc-gen-go: generate Enum method even on proto3

A proto2 message can reference a proto3 enum. It is currently cumbersome
to set proto3 enums in proto2 messages. Add the Enum method in all situations
to support this situation. It also removes yet another point of divergence
between proto2 and proto3.

We could consider removing this method if Go ever gets generics,
but that hypothetical future is long ways away.

Change-Id: Ib83bc87e46b49f3271b90bacb2893bb8e278e4f2
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/177257
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/testprotos/conformance/conformance.pb.go b/internal/testprotos/conformance/conformance.pb.go
index 0dc0735..b54a74d 100644
--- a/internal/testprotos/conformance/conformance.pb.go
+++ b/internal/testprotos/conformance/conformance.pb.go
@@ -41,6 +41,12 @@
 	"TEXT_FORMAT": 4,
 }
 
+func (x WireFormat) Enum() *WireFormat {
+	p := new(WireFormat)
+	*p = x
+	return p
+}
+
 func (x WireFormat) String() string {
 	return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
 }
@@ -102,6 +108,12 @@
 	"TEXT_FORMAT_TEST":                 5,
 }
 
+func (x TestCategory) Enum() *TestCategory {
+	p := new(TestCategory)
+	*p = x
+	return p
+}
+
 func (x TestCategory) String() string {
 	return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
 }
diff --git a/internal/testprotos/conformance/test_messages_proto3.pb.go b/internal/testprotos/conformance/test_messages_proto3.pb.go
index 9cbfbe9..556efd8 100644
--- a/internal/testprotos/conformance/test_messages_proto3.pb.go
+++ b/internal/testprotos/conformance/test_messages_proto3.pb.go
@@ -41,6 +41,12 @@
 	"FOREIGN_BAZ": 2,
 }
 
+func (x ForeignEnum) Enum() *ForeignEnum {
+	p := new(ForeignEnum)
+	*p = x
+	return p
+}
+
 func (x ForeignEnum) String() string {
 	return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
 }
@@ -88,6 +94,12 @@
 	"NEG": -1,
 }
 
+func (x TestAllTypesProto3_NestedEnum) Enum() *TestAllTypesProto3_NestedEnum {
+	p := new(TestAllTypesProto3_NestedEnum)
+	*p = x
+	return p
+}
+
 func (x TestAllTypesProto3_NestedEnum) String() string {
 	return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
 }
@@ -141,6 +153,12 @@
 	"bAz":       2,
 }
 
+func (x TestAllTypesProto3_AliasedEnum) Enum() *TestAllTypesProto3_AliasedEnum {
+	p := new(TestAllTypesProto3_AliasedEnum)
+	*p = x
+	return p
+}
+
 func (x TestAllTypesProto3_AliasedEnum) String() string {
 	return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
 }
diff --git a/internal/testprotos/test3/test.pb.go b/internal/testprotos/test3/test.pb.go
index ded5e83..31180d0 100644
--- a/internal/testprotos/test3/test.pb.go
+++ b/internal/testprotos/test3/test.pb.go
@@ -38,6 +38,12 @@
 	"FOREIGN_BAZ":  6,
 }
 
+func (x ForeignEnum) Enum() *ForeignEnum {
+	p := new(ForeignEnum)
+	*p = x
+	return p
+}
+
 func (x ForeignEnum) String() string {
 	return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
 }
@@ -85,6 +91,12 @@
 	"NEG": -1,
 }
 
+func (x TestAllTypes_NestedEnum) Enum() *TestAllTypes_NestedEnum {
+	p := new(TestAllTypes_NestedEnum)
+	*p = x
+	return p
+}
+
 func (x TestAllTypes_NestedEnum) String() string {
 	return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
 }
diff --git a/internal/testprotos/test3/test_import.pb.go b/internal/testprotos/test3/test_import.pb.go
index 8376505..a281989 100644
--- a/internal/testprotos/test3/test_import.pb.go
+++ b/internal/testprotos/test3/test_import.pb.go
@@ -29,6 +29,12 @@
 	"IMPORT_ZERO": 0,
 }
 
+func (x ImportEnum) Enum() *ImportEnum {
+	p := new(ImportEnum)
+	*p = x
+	return p
+}
+
 func (x ImportEnum) String() string {
 	return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
 }