Skip to content

Commit

Permalink
Fix rs codegen breakage from a field 'bool clear'
Browse files Browse the repository at this point in the history
Before this fix, the overload resolution rules would accidentally attempt to call the accessor named clear() instead of the fn that would actually clear the message (Rust automatically prefers an inherent impl fn over a trait impl fn if both exist with the same name).

PiperOrigin-RevId: 713309633
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jan 8, 2025
1 parent 46ba82b commit 871c434
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions rust/test/bad_names.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ message Self {
optional bool true = 3;
optional string false = 4;
repeated int32 match = 5;
optional bool clear = 6;
}

message Pub {
Expand Down
3 changes: 2 additions & 1 deletion src/google/protobuf/compiler/rust/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,8 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
impl $pb$::Clear for $Msg$ {
fn clear(&mut self) {
self.as_mut().clear()
let mut m = self.as_mut();
$pb$::Clear::clear(&mut m)
}
}
Expand Down

0 comments on commit 871c434

Please sign in to comment.