Skip to content

Commit

Permalink
Add allow dead_code to the oneof case enum.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Dec 19, 2023
1 parent 7315f6d commit 63c3fad
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/google/protobuf/compiler/rust/oneof.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand Down Expand Up @@ -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");
}
}},
Expand Down Expand Up @@ -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")}},
Expand Down

0 comments on commit 63c3fad

Please sign in to comment.