Skip to content

Commit 40268d9

Browse files
authored
THRIFT-6058: fix Rust codegen for list<union> and set<union> deserialization (#3545)
The Rust code generator produces incorrect deserialization code for list<UnionType> and set<UnionType> fields. Two bugs: 1. Variable shadowing: the match binding Ok(val) shadows the outer list/set variable val, so val.push(val) calls push on the element instead of the collection. 2. Missing Box::new(): the collection type is Vec<Box<UnionType>> but the element is pushed without wrapping in Box::new(). Fix: rename the match binding to elem and wrap with Box::new(). The single-field deserialization path (render_struct_sync_read) already handles this correctly; only the collection paths were affected.
1 parent 7d9a69a commit 40268d9

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎compiler/cpp/src/thrift/generate/t_rs_generator.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,7 +2013,7 @@ void t_rs_generator::render_list_sync_read(t_list* tlist, const string& list_var
20132013
string read_call(resolved_type + "::read_from_in_protocol(i_prot)");
20142014
f_gen_ << indent() << "match " << read_call << " {" << '\n';
20152015
indent_up();
2016-
f_gen_ << indent() << "Ok(val) => { " << list_var << ".push(val); }," << '\n';
2016+
f_gen_ << indent() << "Ok(elem) => { " << list_var << ".push(Box::new(elem)); }," << '\n';
20172017
f_gen_ << indent() << "Err(thrift::Error::Protocol(ref e)) if e.kind == ProtocolErrorKind::UnknownUnionVariant => { continue; }," << '\n';
20182018
f_gen_ << indent() << "Err(e) => return Err(e)," << '\n';
20192019
indent_down();
@@ -2048,7 +2048,7 @@ void t_rs_generator::render_set_sync_read(t_set* tset, const string& set_var) {
20482048
string read_call(resolved_type + "::read_from_in_protocol(i_prot)");
20492049
f_gen_ << indent() << "match " << read_call << " {" << '\n';
20502050
indent_up();
2051-
f_gen_ << indent() << "Ok(val) => { " << set_var << ".insert(val); }," << '\n';
2051+
f_gen_ << indent() << "Ok(elem) => { " << set_var << ".insert(Box::new(elem)); }," << '\n';
20522052
f_gen_ << indent() << "Err(thrift::Error::Protocol(ref e)) if e.kind == ProtocolErrorKind::UnknownUnionVariant => { continue; }," << '\n';
20532053
f_gen_ << indent() << "Err(e) => return Err(e)," << '\n';
20542054
indent_down();

0 commit comments

Comments
 (0)