Skip to content

Commit

Permalink
Fix message vtable::clear
Browse files Browse the repository at this point in the history
Needed to pass in the message as a parameter to the clearer thunk!

Now the clear() augmentations in accessors_test.rs are working as expected.

PiperOrigin-RevId: 603394469
  • Loading branch information
honglooker authored and copybara-github committed Feb 1, 2024
1 parent 671b61b commit dc7001e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
9 changes: 3 additions & 6 deletions rust/test/shared/accessors_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,7 @@ fn test_message_opt_set() {
assert_that!(msg.optional_nested_message_opt().is_set(), eq(true));

msg.optional_nested_message_mut().clear();
// TODO: b/323222163
// assert_that!(msg.optional_nested_message_mut().is_set(), eq(false));
assert_that!(msg.optional_nested_message_mut().is_set(), eq(false));
}

#[test]
Expand All @@ -724,8 +723,7 @@ fn test_setting_submsg() {
assert_that!(msg.optional_nested_message_mut().is_set(), eq(true));

msg.optional_nested_message_mut().clear();
// TODO: b/323222163
// assert_that!(msg.optional_nested_message_mut().is_set(), eq(false));
assert_that!(msg.optional_nested_message_mut().is_set(), eq(false));
}

#[test]
Expand All @@ -738,8 +736,7 @@ fn test_msg_or_default() {
assert_that!(msg.optional_nested_message_mut().is_set(), eq(true));

msg.optional_nested_message_mut().clear();
// TODO: b/323222163
//assert_that!(msg.optional_nested_message_mut().is_set(), eq(false));
assert_that!(msg.optional_nested_message_mut().is_set(), eq(false));
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions src/google/protobuf/compiler/rust/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
-> Self::AbsentMutData<'_> {
// SAFETY: The raw ptr msg_ref is valid
unsafe {
(present_mutator.optional_vtable().clearer);
(present_mutator.msg_ref().msg());
(present_mutator.optional_vtable().clearer)(present_mutator.msg_ref().msg());
$pbi$::RawVTableOptionalMutatorData::new($pbi$::Private,
present_mutator.msg_ref(),
Expand Down

0 comments on commit dc7001e

Please sign in to comment.