From cdcb6e7b56649941129943a322355bfb1f961b5d Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Mon, 18 Dec 2023 10:38:22 -0800 Subject: [PATCH] Remove warning about unused thunk in singular_scalar Only emit clearer when the field has presence, lest we get a warning about an unused thunk PiperOrigin-RevId: 591943572 --- .../rust/accessors/singular_scalar.cc | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc index db28e7e1ec..bf4d2c2d6a 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc @@ -115,24 +115,25 @@ void SingularScalar::InMsgImpl(Context field) const { } void SingularScalar::InExternC(Context field) const { - field.Emit( - {{"Scalar", PrimitiveRsTypeName(field.desc())}, - {"hazzer_thunk", Thunk(field, "has")}, - {"getter_thunk", Thunk(field, "get")}, - {"setter_thunk", Thunk(field, "set")}, - {"clearer_thunk", Thunk(field, "clear")}, - {"hazzer", - [&] { - if (field.desc().has_presence()) { - field.Emit( - R"rs(fn $hazzer_thunk$(raw_msg: $pbi$::RawMessage) -> bool;)rs"); - } - }}}, - R"rs( - $hazzer$ + field.Emit({{"Scalar", PrimitiveRsTypeName(field.desc())}, + {"hazzer_thunk", Thunk(field, "has")}, + {"getter_thunk", Thunk(field, "get")}, + {"setter_thunk", Thunk(field, "set")}, + {"clearer_thunk", Thunk(field, "clear")}, + {"hazzer_and_clearer", + [&] { + if (field.desc().has_presence()) { + field.Emit( + R"rs( + fn $hazzer_thunk$(raw_msg: $pbi$::RawMessage) -> bool; + fn $clearer_thunk$(raw_msg: $pbi$::RawMessage); + )rs"); + } + }}}, + R"rs( + $hazzer_and_clearer$ fn $getter_thunk$(raw_msg: $pbi$::RawMessage) -> $Scalar$; fn $setter_thunk$(raw_msg: $pbi$::RawMessage, val: $Scalar$); - fn $clearer_thunk$(raw_msg: $pbi$::RawMessage); )rs"); } @@ -145,23 +146,23 @@ void SingularScalar::InThunkCc(Context field) const { {"getter_thunk", Thunk(field, "get")}, {"setter_thunk", Thunk(field, "set")}, {"clearer_thunk", Thunk(field, "clear")}, - {"hazzer", + {"hazzer_and_clearer", [&] { if (field.desc().has_presence()) { field.Emit(R"cc( bool $hazzer_thunk$($QualifiedMsg$* msg) { return msg->has_$field$(); } + void $clearer_thunk$($QualifiedMsg$* msg) { msg->clear_$field$(); } )cc"); } }}}, R"cc( - $hazzer$; + $hazzer_and_clearer$; $Scalar$ $getter_thunk$($QualifiedMsg$* msg) { return msg->$field$(); } void $setter_thunk$($QualifiedMsg$* msg, $Scalar$ val) { msg->set_$field$(val); } - void $clearer_thunk$($QualifiedMsg$* msg) { msg->clear_$field$(); } )cc"); }