Allow string + bytes fields in oneofs (now that the underyling accessors match the expected shape)

PiperOrigin-RevId: 578561161
pull/14580/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent abdcd65246
commit f083530a06
  1. 5
      rust/test/shared/accessors_proto3_test.rs
  2. 5
      rust/test/shared/accessors_test.rs
  3. 4
      src/google/protobuf/compiler/rust/accessors/accessors.cc
  4. 7
      src/google/protobuf/compiler/rust/oneof.cc

@ -200,9 +200,8 @@ fn test_oneof_accessors() {
assert_that!(msg.oneof_field(), matches_pattern!(not_set(_)));
msg.oneof_uint32_set(Some(7));
msg.oneof_bytes_mut().set(b"");
msg.oneof_bytes_mut().set(b"123");
assert_that!(msg.oneof_uint32_opt(), eq(Optional::Unset(0)));
// This should show it set to the OneofBytes but its not supported yet.
assert_that!(msg.oneof_field(), matches_pattern!(not_set(_)));
assert_that!(msg.oneof_field(), matches_pattern!(OneofBytes(eq(b"123"))));
}

@ -690,11 +690,10 @@ fn test_oneof_accessors() {
assert_that!(msg.oneof_field(), matches_pattern!(not_set(_)));
msg.oneof_uint32_set(Some(7));
msg.oneof_bytes_mut().set(b"");
msg.oneof_bytes_mut().set(b"123");
assert_that!(msg.oneof_uint32_opt(), eq(Optional::Unset(0)));
// This should show it set to the OneofBytes but its not supported yet.
assert_that!(msg.oneof_field(), matches_pattern!(not_set(_)));
assert_that!(msg.oneof_field(), matches_pattern!(OneofBytes(eq(b"123"))));
}
macro_rules! generate_repeated_numeric_test {

@ -23,8 +23,8 @@ namespace {
std::unique_ptr<AccessorGenerator> AccessorGeneratorFor(
const FieldDescriptor& desc) {
// We do not support [ctype=FOO] (used to set the field type in C++ to
// cord or string_piece) in V0 API.
// TODO: We do not support [ctype=FOO] (used to set the field
// type in C++ to cord or string_piece) in V0.6 API.
if (desc.options().has_ctype()) {
return std::make_unique<UnsupportedField>();
}

@ -92,12 +92,15 @@ std::string oneofCaseEnumName(const OneofDescriptor& desc) {
// TODO: Promote up to naming.h once all types can be spelled.
std::string RsTypeName(const FieldDescriptor& desc) {
// TODO: Fields with a ctype set not supported in v0.6 api.
if (desc.options().has_ctype()) {
return "";
}
switch (desc.type()) {
case FieldDescriptor::TYPE_MESSAGE:
case FieldDescriptor::TYPE_ENUM:
case FieldDescriptor::TYPE_GROUP:
case FieldDescriptor::TYPE_STRING:
case FieldDescriptor::TYPE_BYTES:
return "";
default:
return PrimitiveRsTypeName(desc);

Loading…
Cancel
Save