Skip to content

Commit 19d2092

Browse files
Automated rollback of commit 901729e.
PiperOrigin-RevId: 843333974
1 parent 1041d62 commit 19d2092

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/google/protobuf/descriptor.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3957,7 +3957,7 @@ void FieldDescriptor::DebugString(
39573957

39583958
// Label is omitted for maps, oneof, and plain proto3 fields.
39593959
if (is_map() || real_containing_oneof() ||
3960-
(!is_required() && !is_repeated() && !has_presence())) {
3960+
(!is_required() && !is_repeated() && !has_optional_keyword())) {
39613961
label.clear();
39623962
}
39633963
// Label is omitted for optional and required fields under editions.
@@ -4279,6 +4279,12 @@ bool FieldDescriptor::legacy_enum_field_treated_as_closed() const {
42794279
enum_type()->is_closed());
42804280
}
42814281

4282+
bool FieldDescriptor::has_optional_keyword() const {
4283+
return proto3_optional_ ||
4284+
(file()->edition() == Edition::EDITION_PROTO2 && !is_required() &&
4285+
!is_repeated() && !containing_oneof());
4286+
}
4287+
42824288
FieldDescriptor::CppStringType FieldDescriptor::CalculateCppStringType() const {
42834289
ABSL_DCHECK(cpp_type() == FieldDescriptor::CPPTYPE_STRING);
42844290

src/google/protobuf/descriptor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,11 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase,
11351135
int legacy_proto_ctype() const { return legacy_proto_ctype_; }
11361136
bool has_legacy_proto_ctype() const;
11371137

1138+
// Returns true if this field was syntactically written with "optional" in the
1139+
// .proto file. Excludes singular proto3 fields that do not have a label.
1140+
ABSL_DEPRECATED("Use has_presence() instead.")
1141+
bool has_optional_keyword() const;
1142+
11381143
// Get the merged features that apply to this field. These are specified in
11391144
// the .proto file through the feature options in the message definition.
11401145
// Allowed features are defined by Features in descriptor.proto, along with

0 commit comments

Comments
 (0)