santiagomed opened a new pull request, #3545:
URL: https://github.com/apache/thrift/pull/3545

   ## Problem
   
   The Rust code generator produces incorrect deserialization code for 
`list<UnionType>` and `set<UnionType>` fields in structs.
   
   In `t_rs_generator::render_list_sync_read`, when the list element type is a 
union, the generated code is:
   
   ```rust
   match UnionType::read_from_in_protocol(i_prot) {
       Ok(val) => { val.push(val); },
       ...
   }
   ```
   
   Two bugs:
   
   1. **Variable shadowing**: the match binding `Ok(val)` shadows the outer 
list variable `val`, so `val.push(val)` calls `.push()` on the union element 
instead of the `Vec`.
   2. **Missing `Box::new()`**: the list type is `Vec<Box<UnionType>>` but the 
element is not wrapped in `Box::new()` before pushing.
   
   Same bug in `render_set_sync_read` (line 2051).
   
   The single-field deserialization path (`render_struct_sync_read`, line 1718) 
already handles boxing correctly; only the collection paths were affected.
   
   ## Fix
   
   Rename the match binding from `val` to `elem` and wrap with `Box::new()`:
   
   ```rust
   Ok(elem) => { val.push(Box::new(elem)); },
   ```
   
   ## Reproduction
   
   Any `.thrift` file with a struct containing a `list<MyUnion>` field where 
`MyUnion` is a `union` type produces uncompilable Rust code.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to