diff --git a/src/google/protobuf/compiler/rust/accessors/accessors.cc b/src/google/protobuf/compiler/rust/accessors/accessors.cc index ed1e7fcfdf..0e6991a3b2 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessors.cc +++ b/src/google/protobuf/compiler/rust/accessors/accessors.cc @@ -27,14 +27,14 @@ namespace { std::unique_ptr AccessorGeneratorFor( Context& ctx, const FieldDescriptor& field) { - // TODO: We do not support ctype=CORD fields or repeated - // ctype=STRING_PIECE fields on cpp kernel yet (upb doesn't care about ctype). - auto ctype = field.options().ctype(); - if (ctx.is_cpp() && - (ctype == FieldOptions::CORD || ctype == FieldOptions::STRING_PIECE) && - field.is_repeated()) { + // TODO: We do not support repeated strings on C++ kernel if + // they are not string_view or string type. + if (ctx.is_cpp() && field.is_repeated() && + field.cpp_type() == FieldDescriptor::CPPTYPE_STRING && + field.cpp_string_type() != FieldDescriptor::CppStringType::kView && + field.cpp_string_type() != FieldDescriptor::CppStringType::kString) { return std::make_unique( - "fields has an unsupported ctype"); + "unsupported repeated string type"); } if (field.is_map()) { @@ -57,7 +57,8 @@ std::unique_ptr AccessorGeneratorFor( return std::make_unique(); case RustFieldType::BYTES: case RustFieldType::STRING: - if (ctype == FieldOptions::CORD) { + if (ctx.is_cpp() && + field.cpp_string_type() == FieldDescriptor::CppStringType::kCord) { return std::make_unique(); } return std::make_unique(); diff --git a/src/google/protobuf/compiler/rust/accessors/with_presence.cc b/src/google/protobuf/compiler/rust/accessors/with_presence.cc index 7f2f15f77a..d5e9b18c9f 100644 --- a/src/google/protobuf/compiler/rust/accessors/with_presence.cc +++ b/src/google/protobuf/compiler/rust/accessors/with_presence.cc @@ -83,7 +83,12 @@ void WithPresenceAccessorsInMsgImpl(Context& ctx, const FieldDescriptor& field, {"opt_getter", [&] { // Cord fields don't support the _opt getter. - if (field.options().ctype() == FieldOptions::CORD) return; + if (ctx.is_cpp() && + field.cpp_type() == FieldDescriptor::CPPTYPE_STRING && + field.cpp_string_type() == + FieldDescriptor::CppStringType::kCord) { + return; + } ctx.Emit( R"rs( pub fn $raw_field_name$_opt($view_self$) -> $pb$::Optional<$view_type$> { diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index a7e40c219f..3d74643348 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -83,7 +83,9 @@ namespace rust { namespace { // A user-friendly rust type for a view of this field with lifetime 'msg. std::string RsTypeNameView(Context& ctx, const FieldDescriptor& field) { - if (field.options().has_ctype()) { + if (ctx.is_cpp() && field.cpp_type() == FieldDescriptor::CPPTYPE_STRING && + field.cpp_string_type() != FieldDescriptor::CppStringType::kView && + field.cpp_string_type() != FieldDescriptor::CppStringType::kString) { return ""; // TODO: b/308792377 - ctype fields not supported yet. } switch (GetRustFieldType(field.type())) {