In Rust We Trust – A Transpiler from Unsafe C to Safer Rust

Ling, Michael; Yu, Yijun; Wu, Haitao; Wang, Yuan; Cordy, James and Hassan, Ahmed (2022). In Rust We Trust – A Transpiler from Unsafe C to Safer Rust. In: 2022 IEEE/ACM 44th International Conference on Software Engineering: Companion Proceedings (ICSE-Companion), 22-24 May 2022, Pittsburgh, USA, pp. 354–355.



Rust is a type-safe language for system programming with a compiler checking memory and concurrency safety. For a smooth transition from an existing C project, a source-to-source transpiler can auto-transform C programs into Rust using program transformation. However, existing C-to-Rust transformation tools (e.g. the open-source C2Rust transpiler project) have the drawback of preserving the unsafe semantics of C, while rewriting them in Rust's syntax. By relaxing the semantics-preserving constraints of transformations, in this paper, we present CRustS, a fully-automated source-to-source transformation approach, that increases the ratio of the transformed code passing the safety checks of the Rust compiler. Our method uses 220 new Txl source-to-source transformation rules, of which 198 are strictly semantics-preserving and 22 are semantics-approximating, thus reducing the scope of unsafe expressions and exposing more opportunities for safe Rust refactoring. Our method has been evaluated on both open-source and commercial projects, which demonstrates significantly higher safe code ratios after the transformations, with function-level safe code ratios comparable to the average level of idiomatic Rust projects.

Viewing alternatives


Public Attention

Altmetrics from Altmetric

Number of Citations

Citations from Dimensions
No digital document available to download for this item

Item Actions