From 7daa16947b01b9c82d90e7a33294a9ed0dcb4668 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 2 Nov 2023 07:31:50 -0700 Subject: [PATCH] Emit a reason for why a field was unsupported. PiperOrigin-RevId: 578846947 --- .../rust/accessors/accessor_generator.h | 6 ++++++ .../compiler/rust/accessors/accessors.cc | 17 ++++++++++++----- .../rust/accessors/unsupported_field.cc | 4 ++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/google/protobuf/compiler/rust/accessors/accessor_generator.h b/src/google/protobuf/compiler/rust/accessors/accessor_generator.h index 3bf1dca06d..8b26d19dc8 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessor_generator.h +++ b/src/google/protobuf/compiler/rust/accessors/accessor_generator.h @@ -9,6 +9,8 @@ #define GOOGLE_PROTOBUF_COMPILER_RUST_ACCESSORS_ACCESSOR_GENERATOR_H__ #include +#include +#include #include "absl/log/absl_check.h" #include "google/protobuf/compiler/rust/context.h" @@ -96,8 +98,12 @@ class RepeatedScalar final : public AccessorGenerator { class UnsupportedField final : public AccessorGenerator { public: + explicit UnsupportedField(std::string reason) : reason_(std::move(reason)) {} ~UnsupportedField() override = default; void InMsgImpl(Context field) const override; + + private: + std::string reason_; }; } // namespace rust diff --git a/src/google/protobuf/compiler/rust/accessors/accessors.cc b/src/google/protobuf/compiler/rust/accessors/accessors.cc index 807eb478b3..e963e9e075 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessors.cc +++ b/src/google/protobuf/compiler/rust/accessors/accessors.cc @@ -9,6 +9,7 @@ #include +#include "absl/log/absl_log.h" #include "google/protobuf/compiler/rust/accessors/accessor_generator.h" #include "google/protobuf/compiler/rust/context.h" #include "google/protobuf/descriptor.h" @@ -26,7 +27,8 @@ std::unique_ptr AccessorGeneratorFor( // 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(); + return std::make_unique( + "fields with ctype not supported"); } switch (desc.type()) { @@ -50,18 +52,23 @@ std::unique_ptr AccessorGeneratorFor( case FieldDescriptor::TYPE_BYTES: case FieldDescriptor::TYPE_STRING: if (desc.is_repeated()) { - return std::make_unique(); + return std::make_unique("repeated str not supported"); } return std::make_unique(); case FieldDescriptor::TYPE_MESSAGE: if (desc.is_repeated()) { - return std::make_unique(); + return std::make_unique("repeated msg not supported"); } return std::make_unique(); - default: - return std::make_unique(); + case FieldDescriptor::TYPE_ENUM: + return std::make_unique("enum not supported"); + + case FieldDescriptor::TYPE_GROUP: + return std::make_unique("group not supported"); } + + ABSL_LOG(FATAL) << "Unexpected field type: " << desc.type(); } } // namespace diff --git a/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc b/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc index ad0a98901c..e6bce02171 100644 --- a/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc +++ b/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc @@ -16,8 +16,8 @@ namespace compiler { namespace rust { void UnsupportedField::InMsgImpl(Context field) const { - field.Emit(R"rs( - // Unsupported! :( + field.Emit({{"reason", reason_}}, R"rs( + // Unsupported! :( Reason: $reason$ )rs"); field.printer().PrintRaw("\n"); }