From 63c3fad187a7653049feacc19ed753ef73418f05 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 18 Dec 2023 18:10:41 -0800 Subject: [PATCH] Add allow dead_code to the oneof case enum. Without this it shows up as a spurious warning of dead code from never constructed enum cases (rustc can't 'see' that the value can come across from C++) PiperOrigin-RevId: 592064099 --- src/google/protobuf/compiler/rust/oneof.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index ce6e3af3c523a..5b1aff1fbd843 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -244,6 +244,7 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) { R"rs( #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq)] + #[allow(dead_code)] pub(super) enum $case_enum_name$ { $cases$ @@ -274,7 +275,8 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { {"rs_getter", field.name()}, {"type", rs_type}, }, - R"rs($Msg$_::$case_enum_name$::$case$ => $Msg$_::$view_enum_name$::$case$(self.$rs_getter$()), + R"rs( + $Msg$_::$case_enum_name$::$case$ => $Msg$_::$view_enum_name$::$case$(self.$rs_getter$()), )rs"); } }}, @@ -309,8 +311,9 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { field.type() == FieldDescriptor::TYPE_MESSAGE ? "" : ".try_into_mut().unwrap()"}}, - R"rs($Msg$_::$case_enum_name$::$case$ => - $Msg$_::$mut_enum_name$::$case$(self.$rs_mut_getter$()$into_mut_transform$), )rs"); + R"rs( + $Msg$_::$case_enum_name$::$case$ => $Msg$_::$mut_enum_name$::$case$(self.$rs_mut_getter$()$into_mut_transform$), + )rs"); } }}, {"case_thunk", Thunk(ctx, oneof, "case")}},