C to Rust translator

A while ago I've written a converter that prefers to generate readable code over semantically accurate one.

I've then used it to convert lodepng to pure Rust:

However, I'm not pursuing this further, because the result was underwhelming. I've spent a lot of time cleaning the output, only to realize I still have a C-style codebase, I've merely replaced clang with rustc. The minor inaccuracies in translation also introduced bugs. I was lucky lodepng had proper unit tests.

In the process I've realized that converting C code is way more work than just replacing pointers with slices. The are high-level idioms, and architectural choices typical for C programs that don't make a good Rust program. For example, instead of generics it used byte offsets of sizeof(type). It had ad-hoc buffer management and writes to raw pointers for I/O instead of io::Write, etc.

10 Likes