Fix nested enum generation when enums are the sole nested types

PiperOrigin-RevId: 596066421
pull/15308/head
Alyssa Haroldsen 11 months ago committed by Copybara-Service
parent f5b50c5022
commit d1b328ace3
  1. 7
      rust/test/shared/enum_test.rs
  2. 4
      src/google/protobuf/compiler/rust/message.cc

@ -19,6 +19,13 @@ fn test_nested_enum_values() {
assert_that!(i32::from(proto2_unittest::TestAllTypes_::NestedEnum::Neg), eq(-1));
}
#[test]
fn test_isolated_nested_enum() {
// Ensure that the enum is generated even when it's the only nested type for the
// message.
assert_that!(i32::from(proto2_unittest::TestRequiredEnumNoMask_::NestedEnum::Foo), eq(2));
}
#[test]
fn test_enum_value_name_same_as_enum() {
assert_that!(i32::from(enums::TestEnumValueNameSameAsEnum::TestEnumValueNameSameAsEnum), eq(1));

@ -390,9 +390,9 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
}},
{"nested_in_msg",
[&] {
// If we have no nested types or oneofs, bail out without
// If we have no nested types, enums, or oneofs, bail out without
// emitting an empty mod SomeMsg_.
if (msg.nested_type_count() == 0 &&
if (msg.nested_type_count() == 0 && msg.enum_type_count() == 0 &&
msg.real_oneof_decl_count() == 0) {
return;
}

Loading…
Cancel
Save