Skip to content

Comment on Emitting Safer Rust with C2Rustparent

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.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.