Emit a reason for why a field was unsupported.

PiperOrigin-RevId: 578846947
pull/14609/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 725b477032
commit 7daa16947b
  1. 6
      src/google/protobuf/compiler/rust/accessors/accessor_generator.h
  2. 17
      src/google/protobuf/compiler/rust/accessors/accessors.cc
  3. 4
      src/google/protobuf/compiler/rust/accessors/unsupported_field.cc

@ -9,6 +9,8 @@
#define GOOGLE_PROTOBUF_COMPILER_RUST_ACCESSORS_ACCESSOR_GENERATOR_H__
#include <memory>
#include <string>
#include <utility>
#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<FieldDescriptor> field) const override;
private:
std::string reason_;
};
} // namespace rust

@ -9,6 +9,7 @@
#include <memory>
#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<AccessorGenerator> 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<UnsupportedField>();
return std::make_unique<UnsupportedField>(
"fields with ctype not supported");
}
switch (desc.type()) {
@ -50,18 +52,23 @@ std::unique_ptr<AccessorGenerator> AccessorGeneratorFor(
case FieldDescriptor::TYPE_BYTES:
case FieldDescriptor::TYPE_STRING:
if (desc.is_repeated()) {
return std::make_unique<UnsupportedField>();
return std::make_unique<UnsupportedField>("repeated str not supported");
}
return std::make_unique<SingularString>();
case FieldDescriptor::TYPE_MESSAGE:
if (desc.is_repeated()) {
return std::make_unique<UnsupportedField>();
return std::make_unique<UnsupportedField>("repeated msg not supported");
}
return std::make_unique<SingularMessage>();
default:
return std::make_unique<UnsupportedField>();
case FieldDescriptor::TYPE_ENUM:
return std::make_unique<UnsupportedField>("enum not supported");
case FieldDescriptor::TYPE_GROUP:
return std::make_unique<UnsupportedField>("group not supported");
}
ABSL_LOG(FATAL) << "Unexpected field type: " << desc.type();
}
} // namespace

@ -16,8 +16,8 @@ namespace compiler {
namespace rust {
void UnsupportedField::InMsgImpl(Context<FieldDescriptor> field) const {
field.Emit(R"rs(
// Unsupported! :(
field.Emit({{"reason", reason_}}, R"rs(
// Unsupported! :( Reason: $reason$
)rs");
field.printer().PrintRaw("\n");
}

Loading…
Cancel
Save