diff --git a/rust/test/shared/accessors_test.rs b/rust/test/shared/accessors_test.rs index 0587c7de01..5084b218d8 100644 --- a/rust/test/shared/accessors_test.rs +++ b/rust/test/shared/accessors_test.rs @@ -33,11 +33,11 @@ use unittest_proto::proto2_unittest::TestAllTypes; #[test] fn test_default_accessors() { - // defaults are from here: - // http://google3/third_party/protobuf/unittest.proto section default_* let msg = TestAllTypes::new(); assert_eq!(msg.default_int32(), 41); assert_eq!(msg.default_int64(), 42); + assert_eq!(msg.default_sint32(), -45); + assert_eq!(msg.default_sint64(), 46); assert_eq!(msg.default_uint32(), 43); assert_eq!(msg.default_uint64(), 44); assert_eq!(msg.default_bool(), true); @@ -74,6 +74,36 @@ fn test_optional_int64_accessors() { assert_eq!(msg.optional_int64(), 0); } +#[test] +fn test_optional_sint32_accessors() { + let mut msg = TestAllTypes::new(); + assert_eq!(msg.optional_sint32_opt(), None); + assert_eq!(msg.optional_sint32(), 0); + + msg.optional_sint32_set(Some(-22)); + assert_eq!(msg.optional_sint32_opt(), Some(-22)); + assert_eq!(msg.optional_sint32(), -22); + + msg.optional_sint32_set(None); + assert_eq!(msg.optional_sint32_opt(), None); + assert_eq!(msg.optional_sint32(), 0); +} + +#[test] +fn test_optional_sint64_accessors() { + let mut msg = TestAllTypes::new(); + assert_eq!(msg.optional_sint64_opt(), None); + assert_eq!(msg.optional_sint64(), 0); + + msg.optional_sint64_set(Some(7000)); + assert_eq!(msg.optional_sint64_opt(), Some(7000)); + assert_eq!(msg.optional_sint64(), 7000); + + msg.optional_sint64_set(None); + assert_eq!(msg.optional_sint64_opt(), None); + assert_eq!(msg.optional_sint64(), 0); +} + #[test] fn test_optional_uint32_accessors() { let mut msg = TestAllTypes::new(); diff --git a/src/google/protobuf/compiler/rust/accessors/accessors.cc b/src/google/protobuf/compiler/rust/accessors/accessors.cc index fd16be7e9c..482d401735 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessors.cc +++ b/src/google/protobuf/compiler/rust/accessors/accessors.cc @@ -51,6 +51,8 @@ std::unique_ptr AccessorGenerator::For( switch (field.desc().type()) { case FieldDescriptor::TYPE_INT32: case FieldDescriptor::TYPE_INT64: + case FieldDescriptor::TYPE_SINT32: + case FieldDescriptor::TYPE_SINT64: case FieldDescriptor::TYPE_UINT32: case FieldDescriptor::TYPE_UINT64: case FieldDescriptor::TYPE_BOOL: diff --git a/src/google/protobuf/compiler/rust/naming.cc b/src/google/protobuf/compiler/rust/naming.cc index 2e62818a84..44e4ffbcda 100644 --- a/src/google/protobuf/compiler/rust/naming.cc +++ b/src/google/protobuf/compiler/rust/naming.cc @@ -114,6 +114,10 @@ absl::string_view PrimitiveRsTypeName(Context field) { return "i32"; case FieldDescriptor::TYPE_INT64: return "i64"; + case FieldDescriptor::TYPE_SINT32: + return "i32"; + case FieldDescriptor::TYPE_SINT64: + return "i64"; case FieldDescriptor::TYPE_UINT32: return "u32"; case FieldDescriptor::TYPE_UINT64: @@ -135,6 +139,8 @@ bool IsSupportedFieldType(Context field) { (field.desc().type() == FieldDescriptor::TYPE_BOOL || field.desc().type() == FieldDescriptor::TYPE_INT32 || field.desc().type() == FieldDescriptor::TYPE_INT64 || + field.desc().type() == FieldDescriptor::TYPE_SINT32 || + field.desc().type() == FieldDescriptor::TYPE_SINT64 || field.desc().type() == FieldDescriptor::TYPE_UINT32 || field.desc().type() == FieldDescriptor::TYPE_UINT64 || field.desc().type() == FieldDescriptor::TYPE_BYTES);