immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.91k stars 229 forks source link

analyze: rewrite cast target types #908

Open spernsteiner opened 1 year ago

spernsteiner commented 1 year ago

Currently, we don't generate type rewrites for the target types of casts (that is, we never rewrite the T in x as T). Now that all casts have entries in rvalue_tys, I think it should be fairly straightforward to generate rewrites here.

In lighttpd, this produces 12 compile errors.

We'll need to do more work on cast rewriting in the future, since in some cases x as T should be rewritten to some kind of function call. For example, it's not valid to rewrite (x: *const i8) as *const u8 into (x: &[i8]) as &[u8].