diff --git a/rust/test/shared/enum_test.rs b/rust/test/shared/enum_test.rs index ced4c6c4eb..5bf69af040 100644 --- a/rust/test/shared/enum_test.rs +++ b/rust/test/shared/enum_test.rs @@ -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)); diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 4230da200a..6b5bfa877a 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -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; }