Cpp2Rust: Translates C++ to safe Rust automatically
Cpp2Rust is a new tool designed to automatically translate C++ code into safe Rust using Clang's abstract syntax tree. It provides a runtime library to handle C-style pointer semantics while ensuring memory safety.
Why it matters
This tool offers a pathway for legacy C++ codebases to migrate to the memory-safe Rust language, potentially reducing security vulnerabilities in critical software.
Cpp2Rust translates C++ to fully safe Rust automatically. It is a syntax-driven translator based on clang's AST.
Cpp2Rust's algorithm is described in the paper Cpp2Rust: Automatic Translation of C++ to Safe Rust published at PLDI 2026.
Cpp2Rust first parses the input C++ file(s) with clang and produces an AST. It then traverses the AST and emits Rust code as strings, inserting calls to the libcc2rs runtime library where needed (e.g., for raw pointer semantics). Finally, the Rust code is pretty-printed using rustfmt to a single .rs file.
By default the reference counting model is used, which produces fully safe Rust. A generator of unsafe Rust is also available through the --model=unsafe command line argument for debugging and performance comparisons.
Get smarter about the news
Sign up free for a feed built around what you actually care about, Dive Deeper research on any story, and the full text of every article.
Create free accountAlready have an account? Sign in