diff --git a/src/google/protobuf/compiler/rust/context.cc b/src/google/protobuf/compiler/rust/context.cc index ac7b618788..88db9d7cc7 100644 --- a/src/google/protobuf/compiler/rust/context.cc +++ b/src/google/protobuf/compiler/rust/context.cc @@ -67,12 +67,9 @@ absl::StatusOr Options::Parse(absl::string_view param) { auto mapping_arg = absl::c_find_if( args, [](auto& arg) { return arg.first == "bazel_crate_mapping"; }); - if (mapping_arg == args.end()) { - return absl::InvalidArgumentError( - "Mandatory option `mapping` missing, please specify mapping file " - "path."); + if (mapping_arg != args.end()) { + opts.mapping_file_path = mapping_arg->second; } - opts.mapping_file_path = mapping_arg->second; return opts; } diff --git a/src/google/protobuf/compiler/rust/crate_mapping.cc b/src/google/protobuf/compiler/rust/crate_mapping.cc index 7c29a986cd..b8e319021d 100644 --- a/src/google/protobuf/compiler/rust/crate_mapping.cc +++ b/src/google/protobuf/compiler/rust/crate_mapping.cc @@ -23,8 +23,9 @@ namespace rust { absl::StatusOr> GetImportPathToCrateNameMap(const Options* opts) { + absl::flat_hash_map mapping; if (opts->mapping_file_path.empty()) { - return absl::InvalidArgumentError("Mapping file path is not specified"); + return mapping; } std::string mapping_contents; absl::Status status = @@ -33,7 +34,6 @@ GetImportPathToCrateNameMap(const Options* opts) { return status; } - absl::flat_hash_map mapping; std::vector lines = absl::StrSplit(mapping_contents, '\n', absl::SkipEmpty()); size_t len = lines.size(); diff --git a/src/google/protobuf/compiler/rust/crate_mapping_unittest.cc b/src/google/protobuf/compiler/rust/crate_mapping_unittest.cc index 35a91a635e..13d4bf9452 100644 --- a/src/google/protobuf/compiler/rust/crate_mapping_unittest.cc +++ b/src/google/protobuf/compiler/rust/crate_mapping_unittest.cc @@ -15,6 +15,7 @@ using google::protobuf::compiler::rust::Options; using testing::Eq; +using testing::IsEmpty; using testing::UnorderedElementsAreArray; namespace google { @@ -70,14 +71,11 @@ TEST(RustGenerator, GetImportPathToCrateNameMapSimple) { EXPECT_THAT(result.value(), UnorderedElementsAreArray(expected)); } -TEST(RustGenerator, - GetImportPathToCrateNameMapErrorsOnNotSpecifiedMappingFile) { +TEST(RustGenerator, GetImportPathToCrateNameMapForEmptyMappingFile) { const Options opts = {Kernel::kUpb}; auto result = GetImportPathToCrateNameMap(&opts); - EXPECT_FALSE(result.ok()); - EXPECT_THAT(result.status().code(), Eq(absl::StatusCode::kInvalidArgument)); - EXPECT_THAT(result.status().message(), - Eq("Mapping file path is not specified")); + EXPECT_TRUE(result.ok()); + EXPECT_THAT(result.value(), IsEmpty()); } TEST(RustGenerator, GetImportPathToCrateNameMapErrorsOnMissingFile) {