Hacker News new | ask | show | jobs
by boredumb 1191 days ago
C2rust is really cool, but if you're familiar with writing rust and implement even a trivial C function in there it produces something absolutely terrifying. I really enjoy rust and pray I don't find myself working in a code base someone just ran c2rust against.
1 comments

Isn’t the point to generate semantically equivalent Rust code from C, so that you can just get it re-compiling under Rust, and then from there you have a working base from which to start rewriting into safer Rust?
Yes, it’s literally spelled out in TFA:

> this provides a starting point for manual refactoring into idiomatic and safe Rust

This is true, but it still generates a (very) large amount of boilerplate and stylistically suboptimal code. Examples:

- the base unit is the individual C file, which causes structs and symbols to be duplicated across Rust modules

- for loops are translated to while loops with overflowing additions, which is ugly and unnecessary in pretty much every case (this makes sense, semantically, but it could be used only when necessary, not as general strategy)

- variables are declared at the top of the functions (AFAIR)

C2Rust generates code that requires significant refactorings _before_ semantic (C->Rust) translations - as a matter of fact, they had a refactoring tool, but it's been temporarily deprecated.

It's a fantastic tool, but as of now, it requires developers to write their own refactoring tools.