internal/typefmt: move descriptor formatting logic to typefmt

Custom descriptor types would want to benefit from descriptor formatting.
As such, move the logic out from prototype into an internal package for
the benefit of usages outside the prototype package.

Change-Id: I4bb2144221e656aa36909d33a77189fe084f700b
Reviewed-on: https://go-review.googlesource.com/c/152777
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/internal/cmd/generate-types/main.go b/internal/cmd/generate-types/main.go
index 599afc3..d062e0b 100644
--- a/internal/cmd/generate-types/main.go
+++ b/internal/cmd/generate-types/main.go
@@ -180,7 +180,7 @@
 		return {{$nameDesc}}{t}
 	}
 	{{- end}}
-	func (p *{{$nameList}}) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+	func (p *{{$nameList}}) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 	func (p *{{$nameList}}) ProtoInternal(pragma.DoNotImplement) {}
 	{{- end}}
 `))
@@ -201,6 +201,7 @@
 		"sync",
 		"",
 		"github.com/golang/protobuf/v2/internal/pragma",
+		"github.com/golang/protobuf/v2/internal/typefmt",
 		"github.com/golang/protobuf/v2/reflect/protoreflect",
 	} {
 		if pkg == "" {
diff --git a/internal/legacy/extension.go b/internal/legacy/extension.go
index 1c76674..4a074d2 100644
--- a/internal/legacy/extension.go
+++ b/internal/legacy/extension.go
@@ -12,6 +12,7 @@
 	papi "github.com/golang/protobuf/protoapi"
 	ptag "github.com/golang/protobuf/v2/internal/encoding/tag"
 	pimpl "github.com/golang/protobuf/v2/internal/impl"
+	pfmt "github.com/golang/protobuf/v2/internal/typefmt"
 	pvalue "github.com/golang/protobuf/v2/internal/value"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
 	ptype "github.com/golang/protobuf/v2/reflect/prototype"
@@ -248,5 +249,4 @@
 func (x *extensionType) New() interface{}                     { return x.new() }
 func (x *extensionType) ValueOf(v interface{}) pref.Value     { return x.valueOf(v) }
 func (x *extensionType) InterfaceOf(v pref.Value) interface{} { return x.interfaceOf(v) }
-
-// TODO: Provide custom stringer with the new GoType.
+func (x *extensionType) Format(s fmt.State, r rune)           { pfmt.FormatDesc(s, r, x) }
diff --git a/internal/typefmt/desc_test.go b/internal/typefmt/desc_test.go
new file mode 100644
index 0000000..d7d4458
--- /dev/null
+++ b/internal/typefmt/desc_test.go
@@ -0,0 +1,53 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package typefmt
+
+import (
+	"reflect"
+	"testing"
+
+	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
+)
+
+// TestDescriptorAccessors tests that descriptorAccessors is up-to-date.
+func TestDescriptorAccessors(t *testing.T) {
+	ignore := map[string]bool{
+		"DefaultEnumValue": true,
+		"DescriptorByName": true,
+		"ProtoType":        true,
+	}
+	rt := reflect.TypeOf((*pref.Descriptor)(nil)).Elem()
+	for i := 0; i < rt.NumMethod(); i++ {
+		ignore[rt.Method(i).Name] = true
+	}
+
+	for rt, m := range descriptorAccessors {
+		got := map[string]bool{}
+		for _, s := range m {
+			got[s] = true
+		}
+		want := map[string]bool{}
+		for i := 0; i < rt.NumMethod(); i++ {
+			want[rt.Method(i).Name] = true
+		}
+
+		// Check if descriptorAccessors contains a non-existent accessor.
+		// If this test fails, remove the accessor from descriptorAccessors.
+		for s := range got {
+			if !want[s] && !ignore[s] {
+				t.Errorf("%v.%v does not exist", rt, s)
+			}
+		}
+
+		// Check if there are new protoreflect interface methods that are not
+		// handled by the formatter. If this fails, either add the method to
+		// ignore or add them to descriptorAccessors.
+		for s := range want {
+			if !got[s] && !ignore[s] {
+				t.Errorf("%v.%v is not called by formatter", rt, s)
+			}
+		}
+	}
+}
diff --git a/reflect/prototype/stringer.go b/internal/typefmt/stringer.go
similarity index 97%
rename from reflect/prototype/stringer.go
rename to internal/typefmt/stringer.go
index 8400689..21f1072 100644
--- a/reflect/prototype/stringer.go
+++ b/internal/typefmt/stringer.go
@@ -2,7 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package prototype
+// Package typefmt provides functionality to format descriptors.
+package typefmt
 
 import (
 	"fmt"
@@ -21,7 +22,7 @@
 	pragma.DoNotImplement
 }
 
-func formatList(s fmt.State, r rune, vs list) {
+func FormatList(s fmt.State, r rune, vs list) {
 	io.WriteString(s, formatListOpt(vs, true, r == 'v' && (s.Flag('+') || s.Flag('#'))))
 }
 func formatListOpt(vs list, isRoot, allowMulti bool) string {
@@ -94,7 +95,7 @@
 	reflect.TypeOf((*pref.MethodDescriptor)(nil)).Elem():    {"InputType", "OutputType", "IsStreamingClient", "IsStreamingServer"},
 }
 
-func formatDesc(s fmt.State, r rune, t pref.Descriptor) {
+func FormatDesc(s fmt.State, r rune, t pref.Descriptor) {
 	io.WriteString(s, formatDescOpt(t, true, r == 'v' && (s.Flag('+') || s.Flag('#'))))
 }
 func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {
diff --git a/reflect/prototype/desc_test.go b/reflect/prototype/desc_test.go
index 50f1a6d..a8f956e 100644
--- a/reflect/prototype/desc_test.go
+++ b/reflect/prototype/desc_test.go
@@ -57,44 +57,3 @@
 		}
 	}
 }
-
-// TestDescriptorAccessors tests that descriptorAccessors is up-to-date.
-func TestDescriptorAccessors(t *testing.T) {
-	ignore := map[string]bool{
-		"DefaultEnumValue": true,
-		"DescriptorByName": true,
-		"ProtoType":        true,
-	}
-	rt := reflect.TypeOf((*pref.Descriptor)(nil)).Elem()
-	for i := 0; i < rt.NumMethod(); i++ {
-		ignore[rt.Method(i).Name] = true
-	}
-
-	for rt, m := range descriptorAccessors {
-		got := map[string]bool{}
-		for _, s := range m {
-			got[s] = true
-		}
-		want := map[string]bool{}
-		for i := 0; i < rt.NumMethod(); i++ {
-			want[rt.Method(i).Name] = true
-		}
-
-		// Check if descriptorAccessors contains a non-existent accessor.
-		// If this test fails, remove the accessor from descriptorAccessors.
-		for s := range got {
-			if !want[s] && !ignore[s] {
-				t.Errorf("%v.%v does not exist", rt, s)
-			}
-		}
-
-		// Check if there are new protoreflect interface methods that are not
-		// handled by the formatter. If this fails, either add the method to
-		// ignore or add them to descriptorAccessors.
-		for s := range want {
-			if !got[s] && !ignore[s] {
-				t.Errorf("%v.%v is not called by formatter", rt, s)
-			}
-		}
-	}
-}
diff --git a/reflect/prototype/go_type.go b/reflect/prototype/go_type.go
index 4420021..e292608 100644
--- a/reflect/prototype/go_type.go
+++ b/reflect/prototype/go_type.go
@@ -9,6 +9,7 @@
 	"reflect"
 	"sync"
 
+	"github.com/golang/protobuf/v2/internal/typefmt"
 	"github.com/golang/protobuf/v2/internal/value"
 	"github.com/golang/protobuf/v2/reflect/protoreflect"
 )
@@ -43,7 +44,7 @@
 	return e
 }
 func (t *goEnum) Format(s fmt.State, r rune) {
-	formatDesc(s, r, t)
+	typefmt.FormatDesc(s, r, t)
 }
 
 // GoMessage creates a new protoreflect.MessageType by combining the provided
@@ -78,7 +79,7 @@
 	return m
 }
 func (t *goMessage) Format(s fmt.State, r rune) {
-	formatDesc(s, r, t)
+	typefmt.FormatDesc(s, r, t)
 }
 
 // GoExtension creates a new protoreflect.ExtensionType.
@@ -194,7 +195,7 @@
 	return v
 }
 func (t *goExtension) Format(s fmt.State, r rune) {
-	formatDesc(s, r, t)
+	typefmt.FormatDesc(s, r, t)
 }
 func (t *goExtension) lazyInit() {
 	t.once.Do(func() {
diff --git a/reflect/prototype/placeholder_type.go b/reflect/prototype/placeholder_type.go
index 746f388..0838fc2 100644
--- a/reflect/prototype/placeholder_type.go
+++ b/reflect/prototype/placeholder_type.go
@@ -8,6 +8,7 @@
 	"fmt"
 
 	pragma "github.com/golang/protobuf/v2/internal/pragma"
+	pfmt "github.com/golang/protobuf/v2/internal/typefmt"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
@@ -49,7 +50,7 @@
 func (t placeholderFile) Extensions() pref.ExtensionDescriptors          { return &emptyExtensions }
 func (t placeholderFile) Services() pref.ServiceDescriptors              { return &emptyServices }
 func (t placeholderFile) DescriptorByName(pref.FullName) pref.Descriptor { return nil }
-func (t placeholderFile) Format(s fmt.State, r rune)                     { formatDesc(s, r, t) }
+func (t placeholderFile) Format(s fmt.State, r rune)                     { pfmt.FormatDesc(s, r, t) }
 func (t placeholderFile) ProtoType(pref.FileDescriptor)                  {}
 
 type placeholderMessage struct {
@@ -65,7 +66,7 @@
 func (t placeholderMessage) Messages() pref.MessageDescriptors     { return &emptyMessages }
 func (t placeholderMessage) Enums() pref.EnumDescriptors           { return &emptyEnums }
 func (t placeholderMessage) Extensions() pref.ExtensionDescriptors { return &emptyExtensions }
-func (t placeholderMessage) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t placeholderMessage) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t placeholderMessage) ProtoType(pref.MessageDescriptor)      {}
 
 type placeholderEnum struct {
@@ -74,5 +75,5 @@
 
 func (t placeholderEnum) Options() pref.ProtoMessage        { return nil }
 func (t placeholderEnum) Values() pref.EnumValueDescriptors { return &emptyEnumValues }
-func (t placeholderEnum) Format(s fmt.State, r rune)        { formatDesc(s, r, t) }
+func (t placeholderEnum) Format(s fmt.State, r rune)        { pfmt.FormatDesc(s, r, t) }
 func (t placeholderEnum) ProtoType(pref.EnumDescriptor)     {}
diff --git a/reflect/prototype/protofile_list.go b/reflect/prototype/protofile_list.go
index b074ed9..0b3b5ba 100644
--- a/reflect/prototype/protofile_list.go
+++ b/reflect/prototype/protofile_list.go
@@ -10,6 +10,7 @@
 
 	pragma "github.com/golang/protobuf/v2/internal/pragma"
 	pset "github.com/golang/protobuf/v2/internal/set"
+	pfmt "github.com/golang/protobuf/v2/internal/typefmt"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
@@ -34,7 +35,7 @@
 func (p *numbers) Len() int                            { return len(p.ns) }
 func (p *numbers) Get(i int) pref.FieldNumber          { return p.ns[i] }
 func (p *numbers) Has(n pref.FieldNumber) bool         { return p.nss.Has(uint64(n)) }
-func (p *numbers) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *numbers) Format(s fmt.State, r rune)          { pfmt.FormatList(s, r, p) }
 func (p *numbers) ProtoInternal(pragma.DoNotImplement) {}
 
 type ranges [][2]pref.FieldNumber
@@ -49,14 +50,14 @@
 	}
 	return false
 }
-func (p *ranges) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *ranges) Format(s fmt.State, r rune)          { pfmt.FormatList(s, r, p) }
 func (p *ranges) ProtoInternal(pragma.DoNotImplement) {}
 
 type fileImports []pref.FileImport
 
 func (p *fileImports) Len() int                            { return len(*p) }
 func (p *fileImports) Get(i int) pref.FileImport           { return (*p)[i] }
-func (p *fileImports) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *fileImports) Format(s fmt.State, r rune)          { pfmt.FormatList(s, r, p) }
 func (p *fileImports) ProtoInternal(pragma.DoNotImplement) {}
 
 type oneofFieldsMeta struct {
@@ -96,5 +97,5 @@
 func (p *oneofFields) ByName(s pref.Name) pref.FieldDescriptor          { return p.byName[s] }
 func (p *oneofFields) ByJSONName(s string) pref.FieldDescriptor         { return p.byJSON[s] }
 func (p *oneofFields) ByNumber(n pref.FieldNumber) pref.FieldDescriptor { return p.byNum[n] }
-func (p *oneofFields) Format(s fmt.State, r rune)                       { formatList(s, r, p) }
+func (p *oneofFields) Format(s fmt.State, r rune)                       { pfmt.FormatList(s, r, p) }
 func (p *oneofFields) ProtoInternal(pragma.DoNotImplement)              {}
diff --git a/reflect/prototype/protofile_list_gen.go b/reflect/prototype/protofile_list_gen.go
index a6bd5dd..fb3d741 100644
--- a/reflect/prototype/protofile_list_gen.go
+++ b/reflect/prototype/protofile_list_gen.go
@@ -11,6 +11,7 @@
 	"sync"
 
 	"github.com/golang/protobuf/v2/internal/pragma"
+	"github.com/golang/protobuf/v2/internal/typefmt"
 	"github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
@@ -57,7 +58,7 @@
 	}
 	return messageDesc{t}
 }
-func (p *messages) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *messages) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *messages) ProtoInternal(pragma.DoNotImplement) {}
 
 type fieldsMeta struct {
@@ -144,7 +145,7 @@
 	}
 	return fieldDesc{t}
 }
-func (p *fields) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *fields) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *fields) ProtoInternal(pragma.DoNotImplement) {}
 
 type oneofsMeta struct {
@@ -190,7 +191,7 @@
 	}
 	return oneofDesc{t}
 }
-func (p *oneofs) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *oneofs) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *oneofs) ProtoInternal(pragma.DoNotImplement) {}
 
 type extensionsMeta struct {
@@ -236,7 +237,7 @@
 	}
 	return extensionDesc{t}
 }
-func (p *extensions) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *extensions) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *extensions) ProtoInternal(pragma.DoNotImplement) {}
 
 type enumsMeta struct {
@@ -282,7 +283,7 @@
 	}
 	return enumDesc{t}
 }
-func (p *enums) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *enums) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *enums) ProtoInternal(pragma.DoNotImplement) {}
 
 type enumValuesMeta struct {
@@ -348,7 +349,7 @@
 	}
 	return enumValueDesc{t}
 }
-func (p *enumValues) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *enumValues) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *enumValues) ProtoInternal(pragma.DoNotImplement) {}
 
 type servicesMeta struct {
@@ -394,7 +395,7 @@
 	}
 	return serviceDesc{t}
 }
-func (p *services) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *services) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *services) ProtoInternal(pragma.DoNotImplement) {}
 
 type methodsMeta struct {
@@ -440,5 +441,5 @@
 	}
 	return methodDesc{t}
 }
-func (p *methods) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *methods) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *methods) ProtoInternal(pragma.DoNotImplement) {}
diff --git a/reflect/prototype/protofile_type.go b/reflect/prototype/protofile_type.go
index bad93e7..053d8b8 100644
--- a/reflect/prototype/protofile_type.go
+++ b/reflect/prototype/protofile_type.go
@@ -11,6 +11,7 @@
 	"sync"
 
 	pragma "github.com/golang/protobuf/v2/internal/pragma"
+	pfmt "github.com/golang/protobuf/v2/internal/typefmt"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
@@ -69,7 +70,7 @@
 func (t fileDesc) Extensions() pref.ExtensionDescriptors            { return t.f.xs.lazyInit(t, t.f.Extensions) }
 func (t fileDesc) Services() pref.ServiceDescriptors                { return t.f.ss.lazyInit(t, t.f.Services) }
 func (t fileDesc) DescriptorByName(s pref.FullName) pref.Descriptor { return t.f.ds.lookup(t, s) }
-func (t fileDesc) Format(s fmt.State, r rune)                       { formatDesc(s, r, t) }
+func (t fileDesc) Format(s fmt.State, r rune)                       { pfmt.FormatDesc(s, r, t) }
 func (t fileDesc) ProtoType(pref.FileDescriptor)                    {}
 func (t fileDesc) ProtoInternal(pragma.DoNotImplement)              {}
 
@@ -177,7 +178,7 @@
 func (t messageDesc) Messages() pref.MessageDescriptors     { return t.m.ms.lazyInit(t, t.m.Messages) }
 func (t messageDesc) Enums() pref.EnumDescriptors           { return t.m.es.lazyInit(t, t.m.Enums) }
 func (t messageDesc) Extensions() pref.ExtensionDescriptors { return t.m.xs.lazyInit(t, t.m.Extensions) }
-func (t messageDesc) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t messageDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t messageDesc) ProtoType(pref.MessageDescriptor)      {}
 func (t messageDesc) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -231,7 +232,7 @@
 func (t fieldDesc) ExtendedType() pref.MessageDescriptor       { return nil }
 func (t fieldDesc) MessageType() pref.MessageDescriptor        { return t.f.mt.lazyInit(t, &t.f.MessageType) }
 func (t fieldDesc) EnumType() pref.EnumDescriptor              { return t.f.et.lazyInit(t, &t.f.EnumType) }
-func (t fieldDesc) Format(s fmt.State, r rune)                 { formatDesc(s, r, t) }
+func (t fieldDesc) Format(s fmt.State, r rune)                 { pfmt.FormatDesc(s, r, t) }
 func (t fieldDesc) ProtoType(pref.FieldDescriptor)             {}
 func (t fieldDesc) ProtoInternal(pragma.DoNotImplement)        {}
 
@@ -367,7 +368,7 @@
 func (t oneofDesc) DescriptorProto() (pref.Message, bool) { return nil, false }
 func (t oneofDesc) Options() pref.ProtoMessage            { return t.o.Options }
 func (t oneofDesc) Fields() pref.FieldDescriptors         { return t.o.fs.lazyInit(t) }
-func (t oneofDesc) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t oneofDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t oneofDesc) ProtoType(pref.OneofDescriptor)        {}
 func (t oneofDesc) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -407,7 +408,7 @@
 	return t.x.mt.lazyInit(t, &t.x.MessageType)
 }
 func (t extensionDesc) EnumType() pref.EnumDescriptor       { return t.x.et.lazyInit(t, &t.x.EnumType) }
-func (t extensionDesc) Format(s fmt.State, r rune)          { formatDesc(s, r, t) }
+func (t extensionDesc) Format(s fmt.State, r rune)          { pfmt.FormatDesc(s, r, t) }
 func (t extensionDesc) ProtoType(pref.FieldDescriptor)      {}
 func (t extensionDesc) ProtoInternal(pragma.DoNotImplement) {}
 
@@ -427,7 +428,7 @@
 func (t enumDesc) DescriptorProto() (pref.Message, bool) { return nil, false }
 func (t enumDesc) Options() pref.ProtoMessage            { return t.e.Options }
 func (t enumDesc) Values() pref.EnumValueDescriptors     { return t.e.vs.lazyInit(t, t.e.Values) }
-func (t enumDesc) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t enumDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t enumDesc) ProtoType(pref.EnumDescriptor)         {}
 func (t enumDesc) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -445,7 +446,7 @@
 func (t enumValueDesc) DescriptorProto() (pref.Message, bool) { return nil, false }
 func (t enumValueDesc) Options() pref.ProtoMessage            { return t.v.Options }
 func (t enumValueDesc) Number() pref.EnumNumber               { return t.v.Number }
-func (t enumValueDesc) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t enumValueDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t enumValueDesc) ProtoType(pref.EnumValueDescriptor)    {}
 func (t enumValueDesc) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -465,7 +466,7 @@
 func (t serviceDesc) DescriptorProto() (pref.Message, bool) { return nil, false }
 func (t serviceDesc) Options() pref.ProtoMessage            { return t.s.Options }
 func (t serviceDesc) Methods() pref.MethodDescriptors       { return t.s.ms.lazyInit(t, t.s.Methods) }
-func (t serviceDesc) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t serviceDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t serviceDesc) ProtoType(pref.ServiceDescriptor)      {}
 func (t serviceDesc) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -489,7 +490,7 @@
 func (t methodDesc) OutputType() pref.MessageDescriptor    { return t.m.mot.lazyInit(t, &t.m.OutputType) }
 func (t methodDesc) IsStreamingClient() bool               { return t.m.IsStreamingClient }
 func (t methodDesc) IsStreamingServer() bool               { return t.m.IsStreamingServer }
-func (t methodDesc) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t methodDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t methodDesc) ProtoType(pref.MethodDescriptor)       {}
 func (t methodDesc) ProtoInternal(pragma.DoNotImplement)   {}
 
diff --git a/reflect/prototype/standalone_type.go b/reflect/prototype/standalone_type.go
index d13b138..01f694f 100644
--- a/reflect/prototype/standalone_type.go
+++ b/reflect/prototype/standalone_type.go
@@ -7,7 +7,8 @@
 import (
 	"fmt"
 
-	"github.com/golang/protobuf/v2/internal/pragma"
+	pragma "github.com/golang/protobuf/v2/internal/pragma"
+	pfmt "github.com/golang/protobuf/v2/internal/typefmt"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
@@ -29,7 +30,7 @@
 func (t standaloneMessage) Messages() pref.MessageDescriptors     { return &emptyMessages }
 func (t standaloneMessage) Enums() pref.EnumDescriptors           { return &emptyEnums }
 func (t standaloneMessage) Extensions() pref.ExtensionDescriptors { return &emptyExtensions }
-func (t standaloneMessage) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t standaloneMessage) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t standaloneMessage) ProtoType(pref.MessageDescriptor)      {}
 func (t standaloneMessage) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -44,7 +45,7 @@
 func (t standaloneEnum) DescriptorProto() (pref.Message, bool) { return nil, false }
 func (t standaloneEnum) Options() pref.ProtoMessage            { return t.e.Options }
 func (t standaloneEnum) Values() pref.EnumValueDescriptors     { return t.e.vals.lazyInit(t, t.e.Values) }
-func (t standaloneEnum) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t standaloneEnum) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t standaloneEnum) ProtoType(pref.EnumDescriptor)         {}
 func (t standaloneEnum) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -74,6 +75,6 @@
 func (t standaloneExtension) MessageType() pref.MessageDescriptor  { return t.x.MessageType }
 func (t standaloneExtension) EnumType() pref.EnumDescriptor        { return t.x.EnumType }
 func (t standaloneExtension) ExtendedType() pref.MessageDescriptor { return t.x.ExtendedType }
-func (t standaloneExtension) Format(s fmt.State, r rune)           { formatDesc(s, r, t) }
+func (t standaloneExtension) Format(s fmt.State, r rune)           { pfmt.FormatDesc(s, r, t) }
 func (t standaloneExtension) ProtoType(pref.FieldDescriptor)       {}
 func (t standaloneExtension) ProtoInternal(pragma.DoNotImplement)  {}