astronaut0131 opened a new pull request #2228:
URL: https://github.com/apache/thrift/pull/2228


   <!-- Explain the changes in the pull request below: -->
   a trivial change,fix a bug in the rust compiler when using typedef with 
union  
   
   explanation:
   ```
   typedef i32 int
   union Number {
       1: int a
   }
   ```
   this thrift file will generate a  rs file that contains a compile error
   ```
   
   error[E0308]: mismatched types
     --> benchmark/src/main.rs:96:34
      |
   96 |                 o_prot.write_i32(f)?;
      |                                  ^
      |                                  |
      |                                  expected `i32`, found `&i32`
      |                                  help: consider dereferencing the 
borrow: `*f`
   
   error: aborting due to previous error; 2 warnings emitted
   ```
   it's because `ttype` is `t_typedef`
   
https://github.com/apache/thrift/blob/b0d14133d5071370905a1b54b37a1a7c86d50e6d/compiler/cpp/src/thrift/generate/t_rs_generator.cc#L1456
    
https://github.com/apache/thrift/blob/b0d14133d5071370905a1b54b37a1a7c86d50e6d/compiler/cpp/src/thrift/generate/t_rs_generator.cc#L1457
   and `t_typedef`'s `is_base_type()` gives false, but what we need is the 
actual type of `typedef`
   
   so we can fix this bug by getting the actual type of `typedef`
   by 3 lines of code
   ```
         if (ttype->is_typedef()) {
           // get the actual type of typedef
           ttype = ((t_typedef*)ttype)->get_type();
         }
   ```


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to