Add a collision-avoidance behavior to the Rust Proto codegen.
commit55875598f734797804da23c499ba79ca242ef59d
authorProtobuf Team Bot <protobuf-github-bot@google.com>
Wed, 24 Apr 2024 17:39:37 +0000 (24 10:39 -0700)
committerCopybara-Service <copybara-worker@google.com>
Wed, 24 Apr 2024 17:41:46 +0000 (24 10:41 -0700)
treeebe825a2c7b7e6b9576116f8ed0c4d5c30339768
parent849b975e5fce3d181aea692b412826f48c38e087
Add a collision-avoidance behavior to the Rust Proto codegen.

The intent is to avoid codegen issues for simple cases where a message of the shape:
message M {
   int32 x = 3
   string set_x = 8;
}

Which would otherwise break due to the first field having a setter whose name collides with the second field's getter.

By seeing that 'set_x' matches another field with a common accessor prefixed, it will generate all accessors for that field as though it was named `set_x_8`.

This does not avoid all possible collisions, but should mitigate the vast majority of situations of an accidental collision.

PiperOrigin-RevId: 627776907
12 files changed:
rust/test/BUILD
rust/test/bad_names.proto [moved from rust/test/reserved.proto with 53% similarity]
rust/test/shared/BUILD
rust/test/shared/bad_names_test.rs [moved from rust/test/shared/reserved_test.rs with 68% similarity]
src/google/protobuf/compiler/rust/accessors/map.cc
src/google/protobuf/compiler/rust/accessors/repeated_field.cc
src/google/protobuf/compiler/rust/accessors/singular_message.cc
src/google/protobuf/compiler/rust/accessors/singular_scalar.cc
src/google/protobuf/compiler/rust/accessors/singular_string.cc
src/google/protobuf/compiler/rust/naming.cc
src/google/protobuf/compiler/rust/naming.h
src/google/protobuf/compiler/rust/oneof.cc