arXiv:2611.07442cs.SENov 2026

Manuscript Offprint

arXiv:2611.07442

Req2Rust: A Requirements-Guided Agent Harness for Project-Level C++-to-Rust Migration

Shengbo Wang, Mingwei Liu, Yuwen Chen, Yanlin Wang

Shengbo Wang, Mingwei Liu ∗^{*}, Yuwen Chen, and Yanlin Wang

Sun Yat-sen University

wangshb25@mail2.sysu.edu.cn, liumw26@mail.sysu.edu.cn

chenyw95@mail2.sysu.edu.cn, yanlin-wang@outlook.com

Abstract—Memory-safety concerns make Rust an attractive target for modernizing legacy C/C++ systems, yet project-level C++ migration must balance semantic fidelity with Rust-oriented reconstruction. Source-structure-preserving migration can track low-level behavior, but it can also carry source-language organization, unsafe idioms, and project assumptions into Rust. Direct agent-based translation gives the model more freedom to construct a Rust project, but semantic coverage depends on the model identifying the source behaviors that must be preserved. This problem is especially acute for C++, where source behaviors are often hidden in object models, destructor-driven lifetime protocols, and other hard-to-localize C++ semantics.

This paper presents Req2Rust, the first project-level LLM-based C++-to-Rust migration harness. Req2Rust first derives an evidence-grounded Migration Requirements Specification (MRS) that records the behaviors and constraints that must be preserved. It then synthesizes a Rust Design Specification (RDS) and realizes it as an initial Rust project. Because real projects contain implementation details and idioms that only become visible during build and validation, Req2Rust treats the initial Rust project as an executable refinement state. Compiler, semantic, and unsafe-reduction validators produce validation reports for improving buildability, behavioral alignment, and unsafe usage. We evaluate Req2Rust on general C++ projects and modules from the large-scale Openharmony codebase against a ClaudeCode baseline. Req2Rust produces buildable Rust crates in both settings and improves test pass rate from 69.5% to 91.9% on general projects and from 45.4% to 87.9% on Openharmony modules.

Index Terms—C++-to-Rust migration, code translation, requirements engineering, LLMs, agent harnesses

I. INTRODUCTION

Memory-safety vulnerabilities remain a persistent source of systems software failures because they arise from ordinary implementation patterns in memory-unsafe languages. Errors such as out-of-bounds access and use-after-free can be mitigated by static analysis, sanitizers, and hardening techniques, but these approaches operate within languages that still permit unsafe memory behavior. Rust has emerged as a promising alternative because its ownership and borrowing system enforces memory safety at compile time, making it an increasingly attractive target for modernizing legacy C/C++ systems [1]–[5].

However, migrating C/C++ systems to Rust is not merely a translation problem but a project-level redesign problem. Developers must recover intended behavior while reorganizing software around Rust's ownership model, module structure, and ecosystem conventions [6], [7]. This creates a fundamental tension between preserving semantic fidelity and enabling Rust-oriented reconstruction.

A substantial body of prior work has studied C-to-Rust migration, primarily through rule-based translation and refinement-based approaches. These systems demonstrate that C programs can be systematically transformed into Rust while preserving low-level behavior, enabling traceability and incremental safety improvements [7]–[11]. However, they are largely designed for C, where program structure and semantics are comparatively explicit and procedurally organized.

In contrast, C++-to-Rust migration remains significantly more challenging and less explored due to the richer and more implicit semantics of C++. C++ binds program behavior to object models, constructor and destructor lifecycles, template instantiation, overload resolution, callbacks, resource ownership protocols, and build-time conventions. These semantics are often distributed across files and only become observable through cross-module interactions and compilation behavior. As a result, project-level migration cannot rely on local translation alone, but must reason globally about which behaviors must be preserved and which can be restructured in Rust [6], [12].

With the emergence of LLMs, recent work has introduced new possibilities for automated program migration and code translation [13], [14]. LLM-based approaches are effective at local code transformation and iterative repair, and coding-agent systems further extend this capability through execution-driven feedback loops. However, dedicated LLM-based C++-to-Rust work remains sparse, and existing studies mainly operate at the snippet, feature, or translation-unit level rather than project-level reconstruction [12], [15]. These systems also rely on implicit inference of semantic preservation rather than explicit modeling of migration intent. This limitation becomes particularly severe in C++-to-Rust migration, where critical behaviors are often non-local and only observable at the project level.

This reveals a key limitation of existing approaches: without an explicit mechanism to separate what must be preserved from how the target system should be reconstructed, LLM-based migration systems struggle to reliably support project-level C++-to-Rust migration.

Table I summarizes this positioning across representative C/C++-to-Rust migration settings.

Req2Rust addresses this gap through a three-stage

TABLE I POSITIONING OF REQ2RUST AGAINST REPRESENTATIVE C/C++-TO-RUST MIGRATION SETTINGS.

Migration settingRepresentative work/systemMain scopeGap for project-level C++ migration
Rule-based C-to-Rust migrationC2Rust and later C-to-Rust refinement systems [7]-[9], [16]C programs; source-aligned translationWeak C++ object, lifetime, template, and build semantics.
Rule-based C++-to-Rust translationCpp2Rust [6]Supported C++ subset; safe Rust translationLimited end-to-end project reconstruction.
LLM code translation to RustReal-world Rust translation studies and general LLM translation frameworks [13], [14], [17]Function or unit translation with validation/repairNot specialized for project-level C++ reconstruction.
LLM-based C++-to-Rust translationRAG-LLM C++ translation and C++ feature studies [12], [15]Snippet, feature, or translation-unit translationLimited project-wide preservation modeling.
Direct coding-agent migrationClaudeCode and related coding-agent systems [18]Executable repair loopPreservation remains implicit.
Req2RustThis workMRS + RDS + validation reportsProject-level LLM C++-to-Rust reconstruction.

requirements-mediated pipeline. First, it moves preservation decisions out of the model's implicit context and into an MRS, a language-neutral intermediate representation between C++ evidence and Rust implementation. The MRS records externally visible behavior, dependency assumptions, state and resource effects, and safety constraints as preservation obligations. By separating what must be preserved from how Rust will implement it, the MRS helps bridge the source-target language gap before Rust-specific design choices are made.

Second, requirements-guided reconstruction synthesizes an RDS from the MRS and realizes it as an initial Rust project. Third, agent-harnessed refinement treats that project as an executable state. Compiler, semantic, and unsafe-reduction validators produce validation reports for a refinement agent, which iteratively fixes compilation failures, behavioral risks, and reducible unsafe usage. This creates a closed loop between requirements-guided project reconstruction and validator-guided refinement [19].

We evaluate Req2Rust on seven general C++ projects and five Openharmony modules against ClaudeCode. Req2Rust produces buildable Rust crates in both settings and improves test pass rate from 69.5% to 91.9% on general projects and from 45.4% to 87.9% on Openharmony modules. The ablation study shows that semantic validation drives most behavioral gains, while unsafe reduction lowers unsafe usage without reducing the observed test pass rate.

This paper makes the following contributions:

(1) We introduce MRS, a preservation-oriented intermediate representation for project-level C++-to-Rust migration.

(2) We design a requirements-guided reconstruction pipeline that synthesizes an RDS and realizes it as an initial Rust project, followed by agent-harnessed refinement under validation reports.

(3) We evaluate Req2Rust on general C++ projects and Openharmony modules, with ablation studies demonstrating its ability to produce buildable Rust crates with stronger behavioral preservation and lower unsafe usage.

References (35)