Clean up some now-unnecessary or_default()s

PiperOrigin-RevId: 616946153
pull/16214/head
Protobuf Team Bot 8 months ago committed by Copybara-Service
parent dca05ea1cd
commit 06444cb6a1
  1. 2
      rust/proxied.rs
  2. 2
      rust/test/shared/accessors_proto3_test.rs
  3. 10
      rust/test/shared/accessors_test.rs
  4. 8
      rust/test/shared/simple_nested_test.rs

@ -170,7 +170,7 @@ pub trait MutProxy<'msg>: ViewProxy<'msg> {
/// example:
///
/// ```ignore
/// let mut sub: Mut<SubMsg> = msg.submsg_mut().or_default();
/// let mut sub: Mut<SubMsg> = msg.submsg_mut();
/// sub.as_mut().field_x_mut().set(10); // field_x_mut is fn(self)
/// sub.field_y_mut().set(20); // `sub` is now consumed
/// ```

@ -183,7 +183,7 @@ fn test_oneof_accessors() {
assert_that!(msg.oneof_uint32_opt(), eq(Optional::Unset(0)));
assert_that!(msg.oneof_field(), matches_pattern!(not_set(_)));
msg.oneof_nested_message_mut().or_default(); // Cause the nested_message field to become set.
msg.oneof_nested_message_mut(); // Cause the nested_message field to become set.
assert_that!(msg.oneof_bytes_opt(), matches_pattern!(Optional::Unset(_)));
assert_that!(msg.oneof_field(), matches_pattern!(OneofNestedMessage(_)));

@ -492,7 +492,7 @@ fn test_singular_msg_field() {
// testing reading an int inside a view
assert_that!(msg_view.bb(), eq(0));
let mut nested_msg_mut: NestedMessageMut = msg.optional_nested_message_mut().or_default();
let mut nested_msg_mut: NestedMessageMut = msg.optional_nested_message_mut();
// test reading an int inside a mut
assert_that!(nested_msg_mut.bb(), eq(0));
@ -543,12 +543,12 @@ fn test_setting_submsg() {
}
#[test]
fn test_msg_or_default() {
fn test_msg_mut_initializes() {
let mut msg = TestAllTypes::new();
assert_that!(msg.optional_nested_message_opt().is_set(), eq(false));
let _ = msg.optional_nested_message_mut().or_default();
// confirm that that or_default makes the field Present
let _ = msg.optional_nested_message_mut();
// confirm that that optional_nested_message_mut makes the field Present
assert_that!(msg.optional_nested_message_opt().is_set(), eq(true));
msg.clear_optional_nested_message();
@ -757,7 +757,7 @@ fn test_group() {
assert_that!(m.optionalgroup_opt().is_set(), eq(false));
assert_that!(m.optionalgroup().a(), eq(0));
m.optionalgroup_mut().or_default().set_a(7);
m.optionalgroup_mut().set_a(7);
assert_that!(m.optionalgroup_opt().is_set(), eq(true));
assert_that!(m.optionalgroup().a(), eq(7));
}

@ -103,10 +103,10 @@ fn test_recursive_view() {
#[test]
fn test_recursive_mut() {
let mut rec = nested_proto::Recursive::new();
let mut one = rec.rec_mut().or_default();
let mut two = one.rec_mut().or_default();
let mut three = two.rec_mut().or_default();
let mut four = three.rec_mut().or_default();
let mut one = rec.rec_mut();
let mut two = one.rec_mut();
let mut three = two.rec_mut();
let mut four = three.rec_mut();
four.set_num(1);
assert_that!(four.num(), eq(1));

Loading…
Cancel
Save