corrode icon indicating copy to clipboard operation
corrode copied to clipboard

Math on enums generates invalid Rust

Open waywardmonkeys opened this issue 7 years ago • 0 comments

This Rust gets generated:

            (*(*state).result).segment = (SegmentRegister::SEG_ES as (i32) +
                                              (prefix as (i32) - 0x60i32)) as
                (SegmentRegister);

And unfortunately, that's not valid:

error[E0605]: non-primitive cast: `i32` as `asmx86::SegmentRegister`
     --> src/asmx86.rs:10645:42
      |
10645 |               (*(*state).result).segment = (SegmentRegister::SEG_ES as (i32) +
      |  __________________________________________^
10646 | |                                               (prefix as (i32) - 0x60i32)) as
10647 | |                 (SegmentRegister);
      | |_________________________________^
      |
      = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait

Fixing this would require having some code generated that allows converting an integer back to the enum value.

waywardmonkeys avatar Sep 21 '17 13:09 waywardmonkeys