ConceptioArchivearXiv CS
arXiv CSopen access

Towards Reliable C-to-Rust Translation with Rule-Guided Reasoning and Reinforcement Learning

Unknown · 2026 · arxiv_cs
arXiv CS · Papers · License: Open Access · 2026
Open Source ↗Direct PDF ↓
softwarearchitecturesoftwareengineeringtesting
software engineering, software architecture, testing

Towards Reliable C-to-Rust Translation with Rule-Guided Reasoning and Reinforcement Learning Feng Luo

Jiachen Liu

Cuiyun Gao∗

Harbin Institute of Technology, Shenzhen China [email protected]

Harbin Institute of Technology, Shenzhen China [email protected]

Harbin Institute of Technology, Shenzhen China [email protected]

Jia Feng

Kui Liu

Harbin Institute of Technology, Shenzhen China [email protected]

Huawei Software Engineering Application Technology Lab China [email protected]

arXiv:2607.19966v1 [cs.SE] 22 Jul 2026

Abstract The migration of legacy C programs to Rust has become an important direction for improving software memory safety while alleviating the high cost of manual rewriting. Leveraging large language models (LLMs) for automated C-to-Rust translation has emerged as a promising direction. However, existing LLM-based approaches remain limited. On the one hand, LLMs exhibit limited capability in identifying Rust-specific rules, and inadequate handling of Rust syntax often results in incorrect translations. On the other hand, existing LLMs often struggle to accurately capture the semantics of complex code, resulting in incorrect translations. To address these challenges, we propose a Translation fRAmework Via rule-guided reasoning and rEinforcement Learning, namely TRAVEL, consisting of two modules. The first module employs Monte Carlo Tree Search (MCTS)-based reasoning path construction guided by Rust-specific rules, steering the search toward translation steps that respect the syntactic rules that LLMs frequently violate. The second module introduces reinforcement learning that couples execution feedback with reasoning-quality signals, encouraging the model to construct reasoning paths that accurately capture program semantics, thereby ensuring that the generated Rust code preserves the intended behavior of the original C program. We evaluate TRAVEL on three datasets: xCodeEval (a public benchmark), OS-Bench (functions collected from the Linux kernel), and HW-Bench (an industrial dataset from Huawei). On xCodeEval, TRAVEL outperforms all baselines across three backbone LLMs. In particular, compared to the strongest prompting baseline IRENE, TRAVEL improves computational accuracy (CA) by 26.22% and compilation success rate (CSR) by 18.77%. On HW-Bench and OS-Bench, TRAVEL further improves CSR by 18.28% and 16.51%, respectively, while reducing unsafe rate (UR) by 13.06% and 13.08%, respectively.

1

Introduction

Memory-safety vulnerabilities remain the dominant source of critical software flaws in modern systems, and are widely exploited across browsers, operating systems, and cloud infrastructure [10, 19]. Prior studies show that around 70% of vulnerabilities in large codebases such as Microsoft products and Android stem from ∗ Corresponding author.

memory-safety issues in C and C++ [7, 47]. Rust offers memory safety without garbage collection, while retaining the low-level control of C/C++ through its ownership and borrowing model [39]. It has seen increasing adoption in practice, including in the Linux kernel, AWS Firecracker, and security-critical components of Windows [2, 8]. However, manually migrating existing C projects to Rust is costly, as developers must learn Rust’s safety model and preserve the semantics of legacy code. Therefore, automated C-toRust translation, which aims to generate semantically equivalent Rust code, has emerged as a promising direction. Early work on C-to-Rust translation mainly relies on rule-based techniques [23, 30, 54], with C2Rust [27] as a representative system built on Clang [31] and LLVM [29], and follow-up work extending it to specific scenarios such as pointer handling and parallel API migration [11, 12, 22, 55]. While efficient and interpretable, these methods depend heavily on handcrafted expert rules, making them labor-intensive to develop and limited in coverage when faced with the diverse patterns of real-world programs [12, 21]. Recently, large language models (LLMs) have shown strong potential in code generation and translation [34, 41, 42], motivating studies that formulate C-to-Rust translation as a sequenceto-sequence task and learn patterns from large-scale code corpora [13, 51]. However, existing LLM-based methods still face two key challenges. First, LLMs often fail to follow Rust-specific rules, such as ownership, borrowing, and lifetimes (see Fig. 3). These rules are central to Rust’s safety model, but they are not explicitly optimized during pretraining. As a result, LLMs may generate Rust code that violates compilation rules or relies on unsafe constructs to bypass safety checks. Existing methods that use external tools or static feedback [35, 56] mainly repair errors after generation, and thus provide limited guidance during the translation process. Second, LLMs often struggle to accurately capture the semantics of complex code (as shown in Fig. 4). C-to-Rust translation often depends on capturing subtle semantics in the source program. However, these semantics are not explicitly modeled during generation, making it difficult for LLMs to consistently reflect them in the generated code. To address these challenges, we propose TRAVEL, a translation framework via rule-guided reasoning and reinforcement learning, consisting of two key modules:

Luo et al.

• Rule-Guided Reasoning Path Search Module: This module constructs translation reasoning paths using MCTS guided by Rust-specific rules. These rules capture constraints that LLMs often violate, such as ownership, borrowing and lifetimes. By steering the search toward rulecompliant translation steps, this module produces higherquality reasoning trajectories for subsequent training. • Dual-Reward RL Optimization Module: This module trains a reward model to evaluate the quality of translation reasoning paths, and then optimizes the translation policy with GRPO using both reasoning-quality rewards and execution feedback. This encourages the model to preserve the semantics of the original C program while producing Rust code that follows Rust-specific rules. To validate the performance of TRAVEL, We conduct experiments on three datasets: xCodeEval [28], a public function-level benchmark; HW-Bench, an industrial dataset from Huawei; and OS-Bench, a set of 107 C functions collected from the Linux kernel. The three datasets cover complementary domains: xCodeEval focuses on advanced programming and mathematics tasks, while HW-Bench and OS-Bench represent industrial and real-world code scenarios. On xCodeEval, TRAVEL consistently outperforms all baselines across three backbone LLMs, achieving average gains of 35.61% in computational accuracy (CA) and 30.08% in compilation success rate (CSR). On HW-Bench and OS-Bench, TRAVEL further improves CSR by 18.28% and 16.51%, while reducing unsafe rate (UR) by 13.06% and 13.08%, respectively. These results show that TRAVEL is effective for both benchmark programs and real-world C-to-Rust migration scenarios. In summary, our main contributions are as follows: • We identify two key challenges in LLM-based C-to-Rust translation: the limited ability of LLMs to follow Rust-specific rules, and the lack of mechanisms to improve reasoning quality for semantic preservation. • We propose TRAVEL, a novel LLM-based framework that combines rule-guided MCTS and reinforcement learning. The Rule-Guided Reasoning Path Search module discovers translation paths under Rust-specific rule guidance, while the Dual-Reward RL Optimization module improves semantic faithfulness using reasoning-quality rewards and execution feedback. • We conduct extensive experiments on three datasets that cover a broad spectrum of domains, ranging from advanced programming and mathematical tasks to industrial applications and real-world system code. The results show that TRAVEL consistently outperforms all competitive baselines under comparable model sizes. Notably, our 7B model achieves performance competitive with strong proprietary models such as GPT-4o.

2

Methodology

In this section, we propose TRAVEL, a translation framework via rule-guided reasoning path search and reinforcement learning. We first present the overview of TRAVEL and then elaborate on its module details in the following subsections

2.1

Overview

As illustrated in Fig. 1, TRAVEL consists of two main modules. Rule-Guided Reasoning Path Search Module applies MCTS with Rust rule-guided constraints to explore candidate reasoning paths and validates each path against our Verifiable Components (§2.2), propagating execution feedback through the search tree to collect high-quality training triplets (𝐶, 𝑃, 𝑅), where 𝐶 is the C code, 𝑃 is the reasoning path, and 𝑅 is the Rust code. Dual-Reward RL Optimization Module uses these (𝐶, 𝑃, 𝑅) triplets to train a reward model that scores reasoning path quality, initializes the policy via supervised fine-tuning, and then optimizes it with GRPO using a combined reward of an execution reward 𝑟 exec and a reasoning reward 𝑟 reason , encouraging the model to produce translations that are both semantically correct and Rust-compliant.

2.2

Module I: Rule-Guided Reasoning Path Search

This module consists of two components. Verifiable Translation Data Construction provides reliable feedback for semantic preservation and constructs the verifiable data. MCTS-Based Reasoning Path Exploration enables the model to explicitly explore and compare alternative translation trajectories under rule-guided constraints. 2.2.1 Verifiable Components Construction. Evaluating whether a translated Rust program preserves the semantics of the original C code is essential but challenging, as most C-to-Rust datasets lack executable test suites. To address this, we introduce Verifiable Components, which attach test inputs and reference outputs to each C function for semantic verification. Given a C function, we prompt a strong LLM (Qwen2.5-Coder32B-Instruct) to generate 5 test inputs, execute them on the original program, and collect the outputs. These input-output pairs form the Verifiable Components. To verify a Rust translation, we execute it on the same inputs and compare outputs with the references; the translation is considered correct if all outputs match. Verifiable Components are used throughout TRAVEL: Module I uses them to evaluate candidate reasoning paths during MCTS search, while Module II uses them to compute execution rewards for reinforcement learning, enabling semantic verification without pre-existing test cases. 2.2.2 MCTS-Based Reasoning Path Exploration. Monte Carlo Tree Search (MCTS) is a heuristic search algorithm that combines tree search with Monte Carlo sampling. It has gained prominence due to its success in applications such as AlphaGo and is particularly effective for sequential decision-making problems with large and complex state spaces where traditional methods become intractable [9, 43, 44]. We adopt MCTS to explore diverse candidate reasoning paths for C-to-Rust translation, where each path corresponds to a sequence of reasoning steps that progressively transform a C function into its Rust counterpart. Specifically, we formulate reasoning path generation as an MCTS search process. Each node represents an intermediate reasoning state consisting of the accumulated natural-language reasoning trace generated so far, while each action corresponds to generating the next reasoning step conditioned on the current reasoning state.

Towards Reliable C-to-Rust Translation with Rule-Guided Reasoning and Reinforcement Learning

Module Ⅰ: Rule-Guided Reasoning Path Search ①Verifiable Translation Data Construction LLM (Test Cases Gen) C Code

② MCTS-Based Reasoning Path Exploration Monte Carlo Tree Search (MCTS)

Verifiable Components

Selection

C Code

Backpropagation

Paths

Test Reference Cases Output

...

Rules Prompting

Execution

C Code

Expansion

Evaluation

Rust code

Module Ⅱ: Dual-Reward RL Optimization ④ RL Optimization With GRPO

③③Reasoning RewardModel ModelTraining Training Reasoning Reward

Reasoning Reward

�1 C Code

Reasoning Score

�2

...

Paths Policy Model

Reward Model Rust code

Paths

�2

Reward Model

S

...

Execution Reward

��

Loss

�1

�1

��

Group Comput ation

�2

...

��

Execution

Rust Code

Figure 1: Overview of TRAVEL. During MCTS, TRAVEL starts with the initial state as the root and systematically grows the search tree by adding new nodes. Within the context of C-to-Rust translation, we customize the four key operations of the MCTS algorithm as follows: Selection. Starting from the root node 𝑠 0 , the tree T𝑘 is traversed by repeatedly selecting the child with the highest PUCT score [38] until an unexpanded node is reached. PUCT uses the LLM’s prior probability of each action together with visit-based statistics to balance exploitation of high-value paths and exploration of undervisited ones. Formally, at state 𝑠𝑡 we select √︄    𝑁 parent (𝑎)    , (1) 𝑎𝑡 = arg max 𝑄ˆ (𝑠𝑡 , 𝑎) + 𝑐 puct 𝜋𝜃𝑘 (𝑎 | 𝑠𝑡 ) 𝑎∈ T𝑘  1 + 𝑁 (𝑠𝑡 , 𝑎)    where 𝑄ˆ (𝑠𝑡 , 𝑎) is the estimated action value, 𝜋𝜃𝑘 (𝑎 | 𝑠𝑡 ) is the LLM’s prior over actions, 𝑁 (𝑠𝑡 , 𝑎) is the visit count of 𝑎 at 𝑠𝑡 , 𝑁 parent (𝑎) is the visit count of its parent, and 𝑐 puct controls the exploration weight. To bias selection toward idiomatic Rust translations, we guide the LLM’s action prior implicitly through rule-augmented prompts and few-shot examples Expansion. At an unexpanded leaf 𝑠𝑡 , we prompt the LLM to sample 𝐾 candidate next-step actions {𝑎𝑡(1) , . . . , 𝑎𝑡(𝐾 ) }, each spawning a child node 𝑠𝑡(𝑖+1) that extends the current partial translation. To obtain promising steps, in-context exemplars instruct the LLM to wrap every reasoning step between <step> and </step>, and we truncate generation at the first closing tag. The exemplars are

deliberately designed to elicit a two-stage reasoning process within each path: the model first analyzes the source C function’s semantics and then determines how to realize it in Rust by leveraging a Rust-specific translation rule library. Building upon prior C-toRust translation studies [12], we summarize and extend this rule library (Table 1), which provides structured guidance for generating Rust-specific reasoning steps during path construction. This semantics-then-rules organization ensures that every candidate path jointly attends to behavioral correctness and Rust-specific idiomatic compliance, providing the dual-objective supervision later consumed by Module II. Evaluation. When a node 𝑠𝑡 contains a complete Rust translation, we evaluate it with the source function’s Verifiable Components by executing the translation on the recorded test inputs and assigning a binary reward: (

+1, 𝑉ˆ (𝑠𝑡 ) = 𝑟 = −1,

if all test cases pass, if any test case fails,

(2)

where the test cases are those stored in the Verifiable Components of the original C function. Backpropagation. The reward 𝑉ˆ (𝑠𝑡 ) obtained at a terminal node is propagated backward along the selected path, updating the visit counts and action value estimates of all ancestor nodes. Concretely, for each state-action pair (𝑠, 𝑎) on the path, the visit count is incremented as 𝑁 (𝑠, 𝑎) ← 𝑁 (𝑠, 𝑎) + 1, and the action value

Luo et al.

Table 1: Selected Rust translation rules derived from the translation prompt used in TRAVEL. Each rule is illustrated with a representative C-to-Rust transformation example. The complete rules can be found in our repository [16]. Rule

Description

Replace malloc with Ownership

Use ownership types such as Box<T> int *p = malloc(sizeof(int)); *p = or Vec<T> instead of malloc. 42;

C Source

let mut p = Box::new(42i32);

Automatic Memory Management

Do not manually free memory; rely on Rust’s ownership and drop system.

free(p);

(implicit drop when p goes out of scope)

NULL Return Handling

Convert functions returning NULL into Option<T> or Result<T, E>.

int* find() { return NULL; }

fn find() -> Option<i32> { None }

Pointer to Reference

Prefer &T / &mut T over raw pointers when borrowing semantics allow.

int x; int *p = &x;

let x: i32 = 0; let p = &x;

is updated by averaging the propagated rewards: 𝑄ˆ (𝑠, 𝑎) ←

𝑁∑︁ (𝑠,𝑎) 1 𝑉ˆ (𝑠𝑡(𝑖 ) ), 𝑁 (𝑠, 𝑎) 𝑖=1

The objective follows the standard language modeling loss: 𝑁

Module II: Dual-Reward RL Optimization

The goal of this module is to optimize the translation model using the search data collected in Module I. While the Rule-Guided Reasoning Path Search module identifies promising reasoning paths for individual training instances, this module enables the model to internalize and reinforce such reasoning patterns for C-to-Rust translation. To this end, we introduce a dual-reward reinforcement learning framework that jointly optimizes reasoning quality and execution outcomes. Let the data collected from Module I be represented as 𝑁 D = {(𝐶𝑖 , 𝑃𝑖 , 𝑅𝑖 , 𝑣𝑖 )}𝑖=1

Lrm = −

(3)

where 𝑉ˆ (𝑠𝑡(𝑖 ) ) ∈ +1, −1 is the terminal reward defined in Eq. (2) for the 𝑖-th simulation passing through (𝑠, 𝑎). This process encourages future selections to favor trajectories that consistently lead to correct translations. Finally, we aggregate the mean of node value estimates along each reasoning path as its overall score, which is used to assess the quality of the generated reasoning trajectory. After the search terminates, each explored path yields a training triplet (𝐶, 𝑃, 𝑅), where 𝐶 is the input C code, 𝑃 is the reasoning path with its estimated value, and 𝑅 is the resulting Rust translation. These triplets serve as supervision data for the reinforcement learning stage in Module II.

2.3

Rust Target

(4)

where 𝐶𝑖 denotes the input C code, 𝑃𝑖 denotes the reasoning path explored by MCTS, 𝑅𝑖 denotes the corresponding Rust translation generated along that path, and 𝑣𝑖 denotes the reasoning path value estimated by MCTS through verification-based evaluation and backpropagation. Intuitively, 𝑣𝑖 quantifies the quality of a reasoning path in terms of its ability to produce translations that satisfy the executable test cases. 2.3.1 Reward Model Training. We train a reward model to estimate the quality of reasoning paths and their resulting translations. Instead of explicit regression, we formulate reward prediction as a conditional generation task and train the model via supervised fine-tuning (SFT). Given a triplet (𝐶𝑖 , 𝑃𝑖 , 𝑅𝑖 ), the model is trained to generate the corresponding path value 𝑣𝑖 from Module I.

1 ∑︁ log 𝑝𝜙 (𝑣𝑖 | 𝐶𝑖 , 𝑃𝑖 , 𝑅𝑖 ) 𝑁 𝑖=1

(5)

This formulation can be viewed as implicit regression via generative modeling, where continuous reward signals are learned through next-token prediction [3, 33]. Compared to execution-based supervision alone, it provides a denser training signal for evaluating reasoning quality despite sparse binary outcomes from compilation and testing. 2.3.2 Policy Initialization. Before reinforcement learning, we obtain an initial policy model 𝜋𝜃 through a cold-start training stage. Specifically, the model is first supervised on the high-quality search data collected from Module I, so that it learns to generate Rust code conditioned on structured reasoning paths. Formally, for each training example (𝐶𝑖 , 𝑃𝑖 , 𝑅𝑖 ), the policy is optimized with the standard autoregressive objective: 𝑁

Lsft = −

1 ∑︁ log 𝜋𝜃 (𝑃𝑖 , 𝑅𝑖 | 𝐶𝑖 ). 𝑁 𝑖=1

(6)

This initialization provides a reasonable behavioral prior over the task, enabling well-formed reasoning paths and translations. 2.3.3 Dual-Reward GRPO Optimization. After cold-start initialization, we further optimize the policy model using Group Relative Policy Optimization (GRPO) [20]. Optimization Objective. For each input C function 𝐶, GRPO [20] samples a group of 𝐺 outputs {𝑜 (𝑘 ) }𝐺 from the previous policy 𝑘=1 𝜋𝜃 old , where each 𝑜 (𝑘 ) = (𝑃 (𝑘 ) , 𝑅 (𝑘 ) ) pairs a reasoning path with its resulting Rust translation. The current policy 𝜋𝜃 is then updated by maximizing JGRPO (𝜃 ) = E𝐶, {𝑜 (𝑘 ) }∼𝜋𝜃 1 𝐺

𝐺  ∑︁

old

(· |𝐶 )

min 𝜌𝑘 (𝜃 ) 𝐴 (𝑘 ) , clip(𝜌𝑘 (𝜃 ), 1 − 𝜀, 1 + 𝜀) 𝐴 (𝑘 )



𝑘=1

− 𝛽 DKL 𝜋𝜃 ∥ 𝜋𝜃 ref



,

(7) where 𝜌𝑘 (𝜃 ) = 𝜋𝜃 (𝑜 (𝑘 ) | 𝐶)/𝜋𝜃 old (𝑜 (𝑘 ) | 𝐶) is the importance ratio, 𝜀 is the clipping range, and 𝛽 controls the KL penalty strength.

Towards Reliable C-to-Rust Translation with Rule-Guided Reasoning and Reinforcement Learning

The advantage 𝐴 (𝑘 ) is computed by normalizing rewards within the sampled group, eliminating the need for a separate value network: 𝑟 (𝑘 ) − mean({𝑟 ( 𝑗 ) }𝐺𝑗=1 ) , (8) 𝐴 (𝑘 ) = std({𝑟 ( 𝑗 ) }𝐺𝑗=1 ) where 𝑟 (𝑘 ) = 𝑟 (𝐶, 𝑃 (𝑘 ) , 𝑅 (𝑘 ) ) is the combined reward defined above. The KL divergence is estimated via the unbiased estimator: 𝜋𝜃 (𝑜 (𝑘 ) | 𝐶)  𝜋𝜃 (𝑜 (𝑘 ) | 𝐶) − log ref (𝑘 ) − 1, (9) DKL 𝜋𝜃 ∥ 𝜋𝜃 ref = ref (𝑘 ) 𝜋𝜃 (𝑜 | 𝐶) 𝜋𝜃 (𝑜 | 𝐶) where 𝜋𝜃 ref is the SFT-tuned reference policy obtained before reinforcement learning. This term keeps the updated policy from drifting excessively from the reference, ensuring training stability. Execution Reward. The execution reward evaluates the final Rust translation based on executable outcomes. Given a generated Rust program 𝑅, we first check whether it compiles successfully. If compilation fails, a penalty of −1 is assigned. Otherwise, we execute 𝑅 on the test cases derived from the Verifiable Components of the original C program, and compute the pass rate: 𝑛 pass PassRate(𝑅) = , (10) 𝑛 total where 𝑛 pass and 𝑛 total denote the number of passed and total test cases, respectively. If no test case is passed, we assign a reward of −1; otherwise, the reward equals the pass rate. Formally,   −1, if 𝑅 fails to compile,    𝑟 exec (𝑅) = −1, (11) if PassRate(𝑅) = 0,    PassRate(𝑅), otherwise.  This design enforces strong penalties for syntactically invalid or completely incorrect programs, while providing graded feedback for partially correct translations. Reasoning Reward. The reasoning reward evaluates the quality of the generated reasoning path and its associated translation using the learned reward model: 𝑟 reason (𝐶, 𝑃, 𝑅) = 𝑓𝜙 (𝐶, 𝑃, 𝑅).

(12)

Unlike the execution reward, which only reflects the quality of the final output, the reasoning reward provides additional supervision on the intermediate translation process. It encourages the model to generate structured and rules-aware reasoning paths that are more likely to lead to reliable translations. Final Reward. We combine the two reward components into a unified reward: 𝑟 (𝐶, 𝑃, 𝑅) = 𝜆exec 𝑟 exec (𝑅) + 𝜆reason 𝑟 reason (𝐶, 𝑃, 𝑅),

(13)

where 𝜆exec and 𝜆reason are balancing coefficients. This design allows the policy to optimize both the final translation quality and the reasoning process that leads to it. Through this dual-reward GRPO optimization, the policy model is encouraged not only to produce correct final translations, but also to generate reasoning paths that are more likely to lead to semantically faithful and Rust-compliant Rust programs. In this way, Module II complements Module I: guided by carefully designed few-shot exemplars, the reasoning paths in Module I first reason about the source program’s semantics and then apply Rust-specific

Table 2: Code characteristics statistics of HW-Bench and OSBench. Benchmark #Samp. Avg. LOC Avg. Depth Max Depth Avg. Derefs. HW-Bench OS-Bench

100 107

15.33 26.02

0.611 0.607

0.890 0.851

2.22 4.45

rules, so that each path jointly strengthens semantic understanding and syntactic handling; Module II’s reinforcement learning further consolidates both capabilities in the translation model itself.

3 Experimental Setup 3.1 Research Questions To evaluate the effectiveness of TRAVEL, we investigate the following research questions: RQ1: How effective is TRAVEL across different model scales for C-to-Rust translation? RQ2: How do the major components of TRAVEL contribute to the final performance? RQ3: How does TRAVEL perform in industrial scenarios?

3.2

Datasets

Training Set. We construct a training dataset based on the training split of xCodeEval [28], comprising 16,639 samples. Each sample consists of the original C source code, a sequence of reasoning paths produced by the Rule-Guided Reasoning Path Search module of TRAVEL in Section 2, and the corresponding Rust translation, where both the C and Rust programs have been validated against test cases. We partition the data into training and validation sets at a 9:1 ratio. Evaluation Set. We construct three evaluation sets to comprehensively assess the effectiveness of TRAVEL. First, we select 515 samples from the evaluation split of xCodeEval, where each C code sample passes all test cases and has a corresponding Rust implementation. To further evaluate the applicability of TRAVEL in real-world open-source and industrial scenarios, we build two additional benchmarks. The first one, OS-Bench, contains 107 opensource C functions collected from the Linux kernel repository [46]. We choose Linux kernel code because it represents large-scale, production-quality system software with complex control flow, low-level memory manipulation, and strict requirements on correctness and safety. These characteristics make it highly aligned with practical enterprise-level C-to-Rust migration demands, while also posing substantial challenges for automated translation. The second one, HW-Bench, consists of 100 C functions randomly sampled from proprietary projects provided by Huawei, covering diverse industrial scenarios. Table 2 further reports the statistics of code characteristics for both benchmarks.

3.3

Baseline Methods

In C-to-Rust translation experiments, we compare TRAVEL with baselines as detailed below. Instruction provides the C code along with the prompt ‘Translate the following C code to Rust’ without any additional demonstration. In-context Learning (ICL) [5]

Luo et al.

includes several translation examples in the prompt to help the model generate the target Rust code. Retrieval-augment generation (RAG) [14] retrieves examples from the corpus similar to the target translation C code and includes them in the input prompt. Vert [51] uses an LLM with a two-stage refinement process. It first applies compiler-suggested fixes to the source code, then feeds the updated code and diagnostics back into the LLM for further correction. IRENE [32] integrates Rust-specific rules and source-code semantics into an LLM-based C-to-Rust translation pipeline, using rule-guided prompting to steer the model toward safer and more idiomatic translations. SFT [52] fine-tunes the backbone model on our training set using standard supervised learning. It can be viewed as an ablated variant of TRAVEL that removes the reinforcement learning stage.

3.4

Implementation Details

Model selection and setup. We use Qwen2.5-Coder-Instruct at 7B and 3B scales [26] and CodeGemma-7B-Instruct [45] as the backbone models for training. To provide a comprehensive comparison, we further include larger open-source models, including Qwen2.5Coder-14B/32B-Instruct and Qwen3-Coder-30B-Instruct [50], as well as closed-source proprietary models such as GPT-4o, GPT-4omini [1], GPT-5.4-mini [36], and Claude-Haiku-4.5 [4]. We download open-source models from HuggingFace [48] and utilize PyTorch [37] for local deployment and inference, while closed-source models are accessed via their official APIs. Implementation of baselines. For ICL, we follow the prior work [17] and randomly sample four examples from the corpus. For RAG, we retrieve the most relevant example using the BM25 algorithm. For Vert, we directly use the replication packages released by the authors and adapt them to our tasks. For IRENE, we select the example with the highest similarity and apply one iteration of refinement. For TRAVEL, the final reward is computed with 𝜆𝑒𝑥𝑒𝑐 = 𝜆𝑟𝑒𝑎𝑠𝑜𝑛 = 0.5, and Qwen2.5-Coder-32B-Instruct is used as the backbone model for MCTS. Hyperparameter and environment settings. For the MCTSbased reasoning path exploration module, we set the maximum number of reasoning steps per search episode to 5. For the GRPObased reinforcement learning training, we use the VERL framework [40] with the following hyperparameters: the number of candidate samples per prompt 𝐺 = 8, the KL divergence coefficient 𝛽 = 0.001, the clipping range 𝜀 = 0.2, the learning rate = 1 × 10−6 , a training batch size of 32 prompts (each with 8 sampled responses), 2 training epochs, and a maximum sequence length of 4096 tokens. We adopt LoRA [25] for parameter-efficient training with rank 𝑟 = 32, scaling factor 𝛼 = 64, and dropout rate = 0. As for the hyperparameters of generation, we configure all LLMs with greedy decoding (temperature = 0, top-p = 1) to produce deterministic outputs. We execute Python programs with Python 3.10.0 and compile all Rust programs with Rust 1.81.0. All experiments are conducted on an Ubuntu-20.04 server equipped with four NVIDIA A100 GPUs.

3.5

Performance Metrics

To evaluate the translation accuracy, we use the following two widely used performance metrics [53] in our evaluation:

Computational Accuracy (CA) evaluates whether the candidate translation generates the same outputs as the reference when given the same inputs. It can be formally defined as: Í𝑁 𝑐𝑎(𝑦𝑘 , 𝑦ˆ𝑘 ) CA = 𝑘=1 (14) 𝑁 ( 1, if 𝐸𝑥𝑒𝑐𝑘 (𝑦𝑘 ) = 𝐸𝑥𝑒𝑐𝑘 (𝑦ˆ𝑘 ) 𝑐𝑎(𝑦𝑘 , 𝑦ˆ𝑘 ) = (15) 0, otherwise where 𝑁 is the total number of evaluated code samples. 𝑦𝑘 and 𝑦ˆ𝑘 represent the ground truth and the generated translation for the 𝑘-th sample, respectively. 𝐸𝑥 ∈𝐶𝑘 (·) denotes the execution result of a program on the 𝑘-th test case. The indicator function ca(𝑦𝑘 , 𝑦ˆ𝑘 ) equals 1 if both outputs match, and 0 otherwise. Compilation Success Rate (CSR) measures the percentage of translated programs that successfully compile without errors. To evaluate the translation safety, following prior work [56], we use the metrics below: Unsafe Rate (UR) refers to the proportion of unsafe samples in the dataset. Unsafe Loc Rate (ULR) denotes the ratio of unsafe lines of code within each individual sample.

4 Experimental Results 4.1 RQ1: How effective is TRAVEL across different model scales for C-to-Rust translation? To evaluate the overall effectiveness of TRAVEL, we compare TRAVEL with multiple baselines on xCodeEval benchmark. Table 3 reports the results, from which we derive the following findings: Simple prompting yields limited gains in LLMs’ translation ability for C-to-Rust. As shown in Table 3, the promptingbased baselines have limited effectiveness in enhancing model translation capabilities. For instance, Qwen2.5-Coder-7B-Instruct with IRENE only reaches 51.84% CA and 83.88% CSR, while the remaining prompting variants cluster between 34.56% and 38.83% CA. Moreover, prompting baselines generally perform poorly on Codegemma-7B-Instruct; with the exception of IRENE, all other methods achieve at most 19.42% CA and 36.12% CSR. These results suggest that, without parameter-level adaptation, neither in-context examples nor retrieval can teach the model to internalize Rust’s semantic and syntactic constraints, the dual challenge that motivates TRAVEL. TRAVEL effectively improves models’ translation capabilities in C-to-Rust, particularly in semantic understanding and Rust-specific rules syntactic handling. As shown in Table 3, models augmented with TRAVEL demonstrate substantial improvements across all metrics. The model achieves strong performance after SFT, and further improvements are obtained through subsequent reinforcement learning. For Codegemma-7B-Instruct, applying TRAVEL improves performance by 48.19% and 50.26% in terms of CA and CSR on average across all baselines. Notably, TRAVEL outperforms the state-of-the-art baseline SFT by 3.69% and 0.78% on the same metrics. Similarly, for Qwen2.5-Coder-7BInstruct, TRAVEL yields consistent improvements, achieving average gains of 26.77% and 13.53% in CA and CSR, respectively. Both

Towards Reliable C-to-Rust Translation with Rule-Guided Reasoning and Reinforcement Learning

Table 3: Comparison results with baseline models in terms of translation accuracy (CA, CSR) and translation safety (UR, ULR). The bold figures indicate the best results.

Approach

Size/Version

Translation Accuracy CA CSR

Translation Safety UR ULR

Closed-source Proprietary Models GPT-5.4-mini GPT-4o GPT-4o-mini Claude-Haiku-4.5

Mar. 2026 Nov. 2024 July. 2024 Oct. 2025

96.31 69.51 58.25 74.37

99.03 93.59 85.63 95.34

5.83 5.05 5.05 3.11

2.75 2.35 1.73 1.04

59.03 45.44 52.04

87.18 74.17 76.50

0.97 2.52 4.27

0.36 0.67 1.36

15B+ Models Qwen2.5-Coder-32B-Instruct Qwen2.5-Coder-14B-Instruct Qwen3-Coder-30B-Instruct

32B 14B 30B

7B-level And 3B-level Models

Qwen2.5-Coder-7B-Instruct

Instruction ICL RAG Vert IRENE SFT TRAVEL

7B 7B 7B 7B 7B 7B 7B

38.83 34.95 34.56 37.28 51.84 68.35 71.07

67.57 63.50 63.69 76.70 83.88 87.77 87.38

3.11 0.78 0.58 3.11 1.36 0.00 0.00

0.49 0.10 0.17 0.86 0.12 0.00 0.00

Codegemma-7B-Instruct

Instruction ICL RAG Vert IRENE SFT TRAVEL

7B 7B 7B 7B 7B 7B 7B

4.08 19.42 9.71 2.33 32.43 66.99 70.68

10.87 36.12 24.85 9.51 52.82 86.21 86.99

3.50 0.39 0.58 1.75 0.78 0.78 0.78

0.32 0.01 0.05 0.13 0.02 0.03 0.03

Qwen2.5-Coder-3B-Instruct

Instruction ICL RAG Vert IRENE SFT TRAVEL

3B 3B 3B 3B 3B 3B 3B

18.06 20.19 24.66 4.27 37.86 57.86 59.03

36.31 47.38 52.43 22.14 56.50 77.48 75.15

0.19 0.00 0.00 6.99 0.00 0.00 0.00

0.01 0.00 0.00 0.62 0.00 0.00 0.00

SFT and the TRAVEL substantially outperform all prompting baselines, confirming the strength in jointly modeling source semantics and Rust-specific syntactic rules. We observe that on Qwen2.5-Coder-3B/7B-Instruct, TRAVEL yields slightly lower CSR than SFT. This is because our final reward optimizes semantic correctness rather than CSR alone. Although compilation failures are penalized, the execution reward mainly provides graded feedback through test-pass outcomes, while the reasoning reward encourages more semantically faithful reasoning paths. This can make the policy less conservative than SFT, occasionally introducing compilation errors while improving behavioral correctness. Small models augmented with TRAVEL outperform some larger models. By comparing models of different sizes, we find that smaller models enhanced with TRAVEL can outperform substantially larger ones. For example, Qwen2.5-Coder-7B-Instruct+TRAVEL

achieves 71.07% CA and 87.38% CSR on xCodeEval, outperforming Qwen2.5-Coder-32B-Instruct (59.03% CA), Qwen3-Coder-30BInstruct (52.04% CA), and the proprietary GPT-4o-mini (58.25% CA), while closing most of the gap to GPT-4o (69.51% CA). Similarly, Qwen2.5-Coder-3B-Instruct+TRAVEL attains 59.03% CA, on par with Qwen2.5-Coder-32B-Instruct that has roughly 10 times more parameters. These results highlight that through TRAVEL, smaller models can achieve comparable or superior performance to much larger models in C-to-Rust translation. Translation safety. Beyond accuracy, TRAVEL also significantly improves translation safety. For instance, on Qwen2.5-Coder7B-Instruct, TRAVEL reduces UR and ULR by 1.49% and 0.29% on average compared to all baselines. Notably, it also demonstrates substantial advantages over strong closed-source models; for example, on CodeGemma-7B-Instruct, TRAVEL achieves average reductions of 3.98% and 1.94% in UR and ULR, respectively, compared to the four closed-source models shown in Table 3. This indicates that the

Luo et al.

xCodeEval HW-Bench OS-Bench

Figure 2: Application domain distributions of xCodeEval, HW-Bench and OS-Bench.

rule-guided search effectively internalizes Rust safety constraints during training. Answer to RQ1: TRAVEL consistently improves C-toRust translation across backbones of different families and scales: it outperforms all same-scale baselines, matches or exceeds open-source models up to an order of magnitude larger, and narrows the gap to leading proprietary LLMs, while producing markedly safer Rust code with near-zero unsafe usage.

4.2

RQ2: How do the major components of TRAVEL contribute to the final performance?

Effect of the execution reward. As shown in Table 4, removing the execution reward (-w/o Execution Reward) leads to a consistent degradation in performance across all three backbones. For example, on Qwen2.5-Coder-3B-Instruct, CA drops from 59.03% to 55.92% and CSR falls from 75.15% to 71.65%. This confirms that execution-level feedback provides a concrete and verifiable signal that complements the more abstract reasoning-path reward and anchors the optimization in observable behavior. Effect of reinforcement learning. As shown in Table 4, removing the dual-reward RL stage (-w/o RL (SFT with Paths)) results in performance declines across all three backbones. For example, CA drops from 71.07% to 68.35% on Qwen2.5-Coder-7B-Instruct and from 70.68% to 66.99% on Codegemma-7B-Instruct. The marginal CSR rise on the two Qwen backbones reflects a shift in optimization behavior: without RL, the model produces more conservative code that favors compilation, while dual-reward RL encourages semantically richer reasoning that may occasionally introduce compilation errors. Overall, this trade-off is favorable, as CA gains outweigh the small CSR fluctuations. Effect of reasoning-path construction. Comparing SFT w/o Paths against SFT with Paths isolates the contribution of the MCTSconstructed reasoning paths. Across all three backbones, removing the reasoning paths degrades both metrics. For example, on Qwen2.5-Coder-7B-Instruct, CA drops from 68.35% to 67.18% and CSR drops from 87.77% to 83.30%, indicating that the structured reasoning paths supply explicit semantic and rule-level guidance that plain input–output pairs cannot offer. Answer to RQ2: The major components of TRAVEL jointly drive the final performance. Reasoning-path construction contributes the largest single gain, especially on smaller backbones, and the RL stage brings further consistent improvements in CA across all backbones. The reasoning-path and execution rewards play complementary roles: the former favors semantic validity, while the latter balances semantic validity and compilability, and combining them yields the best overall balance on larger backbones.

To quantify the contribution of the major components of TRAVEL, we conduct an ablation study across all three backbone models, as shown in Table 4: • -w/o Reasoning Reward: remove the reasoning-path quality reward, retaining only the execution reward during RL. • -w/o Execution Reward: remove the execution reward, retaining only the reasoning-path quality reward during RL. • -w/o RL (SFT with Paths): disable the RL stage and perform supervised fine-tuning on the MCTS-constructed reasoning paths. • -w/o RL & Paths (SFT w/o Paths): disable both the RL stage and reasoning-path construction, and perform supervised fine-tuning only on input–output pairs. Effect of the reasoning reward. As shown in Table 4, removing the reasoning reward (-w/o Reasoning Reward) consistently lowers CA across all three backbones. For example, CA drops from 71.07% to 70.29% on Qwen2.5-Coder-7B-Instruct and from 70.68% to 69.71% on Codegemma-7B-Instruct, confirming that the reasoning paths encouraged by this reward are highly effective for capturing source semantics. Interestingly, CSR increases on all backbones in this setting. This is because removing the reasoning reward simplifies the optimization signal, leaving the model to rely primarily on execution-based feedback. As a result, the model tends to produce more conservative translations that prioritize compilability, often at the expense of semantic alignment.

4.3

RQ3: How does TRAVEL perform in industrial scenarios?

To assess the applicability of TRAVEL in industrial scenarios, we collaborate with Huawei and randomly select 100 C functions from their product-line codebase, denoted as HW-Bench. As 100 functions from a single industrial codebase may not fully reflect this category of code, we additionally collect 107 C functions from the Linux kernel, denoted as OS-Bench. Together, the two benchmarks offer a more representative view of the C code that real-world Rust migration efforts target. We apply TRAVEL to translate these functions into Rust and compare it against the same baselines used in RQ1. Since no test cases are available for these proprietary or kernel-level functions, the CA metric cannot be computed and we report only CSR, UR, and ULR. The results are shown in Table 5. Comparison of translation accuracy. TRAVEL consistently achieves the highest CSR across most LLMs on both benchmarks.

Towards Reliable C-to-Rust Translation with Rule-Guided Reasoning and Reinforcement Learning

Table 4: Ablation study of the major components of TRAVEL on three backbone models. Qwen2.5-Coder-3B-Instruct CA CSR

Approach

Qwen2.5-Coder-7B-Instruct CA CSR

Codegemma-7B-Instruct CA CSR

-w/o Reasoning Reward -w/o Execution Reward -w/o RL (SFT with Paths) -w/o RL & Paths (SFT w/o Paths)

58.06 55.92 57.86 48.16

77.48 71.65 77.48 70.87

70.29 70.10 68.35 67.18

88.74 88.54 87.77 83.30

69.71 68.35 66.99 65.63

87.57 86.99 86.21 82.52

TRAVEL

59.03

75.15

71.07

87.38

70.68

86.99

Table 5: Performance comparison on HW-Bench and OS-Bench Qwen2.5-Coder-3B-Instruct Approach

HW-Bench

Qwen2.5-Coder-7B-Instruct

OS-Bench

HW-Bench

Codegemma-7B-Instruct

OS-Bench

HW-Bench

OS-Bench

CSR

UR

ULR

CSR

UR

ULR

CSR

UR

ULR

CSR

UR

ULR

CSR

UR

ULR

CSR

UR

ULR

Instruction ICL RAG Vert IRENE SFT

20.00 22.00 27.00 40.00 39.00 49.00

22.00 14.00 17.00 33.00 33.00 11.00

6.98 2.75 5.28 11.02 11.38 1.88

6.54 24.30 13.08 14.02 17.76 28.04

28.04 10.29 19.63 7.46 25.23 10.15 26.17 8.09 37.38 14.90 9.35 2.18

20.00 26.00 36.00 35.00 30.00 51.00

25.00 35.00 38.00 45.00 23.00 10.00

9.14 10.02 10.53 14.59 7.87 2.14

10.28 12.15 12.15 28.97 23.36 41.12

46.73 25.23 35.51 60.75 42.99 27.10

17.70 7.62 13.22 20.76 15.63 5.50

9.00 17.00 14.00 22.00 31.00 35.00

12.00 14.00 20.00 25.00 13.00 7.00

3.27 2.75 8.66 5.06 4.01 1.15

2.80 12.15 6.54 9.35 15.89 13.08

15.89 25.23 23.36 18.69 21.50 4.67

4.58 7.62 7.27 5.27 5.40 1.67

TRAVEL

49.00

5.00

0.67

40.19

10.28

1.91

54.00

19.00

5.69

38.32

24.30

4.14

39.00

3.00

0.29

19.63

8.41

1.59

For example, Qwen2.5-Coder-3B-Instruct augmented with TRAVEL improves CSR by 16.17% on HW-Bench and 22.90% on OS-Bench. Across the three models, TRAVEL yields average CSR improvements of 18.28% and 16.51%, respectively. These results indicate that TRAVEL is effective at producing syntactically valid Rust code for complex industrial programs. Comparison of translation safety. In terms of safety, Table 5 shows that TRAVEL achieves the lowest UR and ULR across most LLMs. On average, TRAVEL reduces UR and ULR by 13.06% and 4.37% on HW-Bench, respectively, and by 13.08% and 6.64% on OS-Bench. These results highlight the superiority of TRAVEL in generating safer Rust code compared to other baselines. Overall, the results indicate that TRAVEL not only performs reliably in the public benchmark, but also generalizes well to industrial scenario. To further characterize the used benchmarks, following prior work [6], we analyze their application-domain distribution (Fig. 2). Both contain a substantially higher proportion of operatingsystem and system-interaction code than xCodeEval, and OS-Bench in particular consists entirely of OS-level functions. Given that the two benchmarks exhibit similar properties, TRAVEL’s strong performance on these benchmarks further shows its robustness in handling real-world systems code.

Answer to RQ3: TRAVEL improves syntactic validity and safety in industrial scenarios. Across HW-Bench and OSBench under three LLMs, TRAVEL achieves an average absolute improvement of 17.40% in CSR, together with average reductions of 13.07% in UR and 5.50% in ULR over baselines.

QWC’s solution Question

TRAVEL’s solution Syntax issue

fn main() { ... let a = [ [numbers[0], numbers[1], numbers[2]], [numbers[3], numbers[4], numbers[5]], [numbers[6], numbers[7], numbers[8]], ]; a[0][0] = x; a[1][1] = y; a[2][2] = z; ... } Compilation Error Reason: `a` is not declared as `mut`, but its array elements are modified later; t Corresponding Rust Rule: Bindings are immutable by default in Rust, and you cannot modify elements of an immutable array.

Question 1. Understand the C program functionality.

2. Identify the required Rust input structure and program form.

3. Apply translation rules and reason about Rust equivalents. The 3x3 C array int a[3][3] can be represented in Rust as a Vec<Vec<i32>> with a fixed size of 3x3.

...

fn main() { ... let mut a: Vec<Vec<i32>> = vec![vec![0; 3]; 3]; ... a[0][0] = x; a[1][1] = y; a[2][2] = z; ... } Pass all test cases

Figure 3: A case demonstrating that Rule-guided MCTS can effectively apply Rust-specific rules to avoid syntax issues. QWC refers to Qwen2.5-Coder-7B-Instruct, which is also used as the backbone of our tool.

5 Discussion 5.1 Why Does TRAVEL Work? In this section, we identify the following two advantages of TRAVEL, which can explain its effectiveness in C-to-Rust translation. For

Luo et al.

SFT’s solution Question

TRAVEL’s solution Semantic issue

Question

1. Understand the C program functionality. It simplifies the result using the GCD, and prints the simplified fraction.

1. Understand the C program functionality. Calculate the difference and divide it by the GCD of the difference and the larger value.

2. Identify the required Rust input structure and program form.

2. Identify the required Rust input structure and program form.

...

fn main() { ... let g = gcd(diff, ad); let numerator = diff / g; let denominator = ad / g; ... } Failed test input: 1 1 3 2 Output: 1/2 Expected output: 1/3 Reason: Step 1 fails to specify that the denominator should be the larger cross product value when simplifying.

...

fn main() { ... let max_val = if a * d > b * c {a * d} else {b * c};

}

let g = gcd(diff, max_val); let numerator = diff / g; let denominator = max_val / g; ...

Pass all test cases

Figure 4: A case showing that dual-reward reinforcement learning further enhances the model’s semantic understanding compared to SFT. All models used here are based on the same backbone, QWC-7B-Instruct.

each advantage, we demonstrate the corresponding cases, as shown in Fig. 3 and Fig. 4. Advantage 1: Rule-guided MCTS enables the model to handle Rust-specific syntactic rules. A common failure of vanilla LLM translation is the violation of Rust-specific constraints (e.g., ownership, borrowing, lifetimes, and FFI signatures) that have no direct counterpart in C. As shown in Fig. 3, the QWC baseline produces a candidate that looks plausible but breaks Rust’s borrow-checker rule, leading to a compilation failure. In contrast, TRAVEL provides rule-aware guidance during each expansion step via prompt conditioning, which biases the search toward ruleconsistent reasoning paths. As a result, the search converges on a translation that simultaneously respects the language-specific rules and preserves the original behavior. This mechanism explains why TRAVEL consistently improves CSR across all backbones. Advantage 2: Dual-reward reinforcement learning improves semantic reasoning. SFT provides reasoning supervision but does not ensure that reasoning paths lead to behavior-preserving Rust code. As shown on the left of Fig. 4, the SFT-only model produces syntactically valid Rust, but fails to capture a key semantic constraint: the denominator should use the larger cross-product value, resulting in incorrect behavior. Our dual-reward RL addresses this by combining a paths reward, which favors rule-aligned reasoning steps, and an execution reward, which favors translations that pass the test suite. These signals guide the model to improve both intermediate reasoning and final outputs. As shown on the right of Fig. 4, GRPO enables the same QWC backbone to correctly identify the larger cross-product value, producing behavior-preserving code that passes all tests.

5.2

Threats to Validity

For our study, we discuss the following threats to validity. Dependence on the underlying LLMs. The effectiveness of TRAVEL may be influenced by the capability of the base LLM used for reasoning path generation and translation. Stronger models may generate better candidate reasoning paths during MCTS, while weaker models may limit the quality of both search and reinforcement learning. To mitigate this threat, we evaluate TRAVEL on multiple representative LLMs rather than relying on a single model. The consistent improvements across models suggest that the effectiveness of TRAVEL does not depend on a specific backbone alone. Imperfect verification from LLM-generated test cases. Our framework relies on LLM-generated tests to construct Verifiable Components for evaluation and reinforcement learning rewards. While this enables scalable semantic verification, such tests may not fully cover corner cases, so translated programs may pass tests yet deviate from the original C code on unseen inputs. Prior work [53] shows that even a 7B model can achieve 87.20% line coverage with five generated tests, suggesting that LLM-generated tests can provide reasonably strong coverage. Given that we use a stronger model (Qwen2.5-Coder-32B-Instruct), we expect comparable or better coverage. To mitigate this threat, we generate multiple test inputs per function and ground all outputs by executing the original C program. Nevertheless, our evaluation reflects test-based semantic verification rather than full formal equivalence. Potential data leakage. As pretraining datasets are not publicly available, we cannot completely rule out potential data leakage. Nevertheless, the limited performance of standard prompting suggests that any such effect is unlikely to be significant. The notable improvements brought by our framework further indicate that the observed gains are attributable to our method rather than simple memorization by the models. Overall, these results support the robustness of our approach and its ability to generalize beyond potential training data overlap.

6

Related Work

Rule-based techniques apply hand-crafted transformations on top of compiler infrastructures to map C idioms onto Rust counterparts. A representative example is C2Rust [27], a Clang/LLVM-based pipeline that produces syntactically equivalent but largely unsafe Rust through the C-Rust FFI, and follow-up work extends it along complementary dimensions, including pointer aliasing [11, 12], concurrent lock APIs [22], ownership inference for pointer-type conversion [55], and generics and standard-library substitution [24, 49]. While interpretable, these approaches rely on expert-defined rules and have limited coverage for real-world programs [21]. LLM-based methods instead cast translation as a sequence generation task and exploit cross-language patterns learned from large code corpora. Vert [51] combines few-shot prompting with compiler feedback, while several approaches incorporate program analysis or hybrid pipelines for iterative repair [35, 56]. Other methods further focus on rewriting raw pointers and eliminating residual safety defects. [15, 18].

Towards Reliable C-to-Rust Translation with Rule-Guided Reasoning and Reinforcement Learning

In contrast, TRAVEL integrates rule-guided MCTS with reinforcement learning to jointly improve rule compliance and semantic preservation, producing translations that are both compilable and behaviorally faithful.

7

Conclusion

In this paper, we propose TRAVEL, an LLM-based framework for C-to-Rust translation. TRAVEL improves translation quality by combining rule-guided reasoning-path search with reinforcement learning to enhance both rule compliance and semantic preservation. Extensive experiments demonstrate that TRAVEL consistently improves translation accuracy across multiple models and datasets. Ablation studies further confirm the effectiveness of each module. In future work, we plan to integrate the TRAVEL-trained model into an agent-based migration framework to support repositorylevel C-to-Rust migration through cross-function reasoning and dependency analysis. We also plan to construct sandbox-based execution environments for larger industrial codebases to enable more scalable and rigorous semantic validation, while extending the framework to support additional programming languages.

Data Availability Statement All data and code are publicly available at [16].

References [1] Josh Achiam, Steven Adler, Sandhini Agarwal, Lama Ahmad, Ilge Akkaya, Florencia Leoni Aleman, Diogo Almeida, Janko Altenschmidt, Sam Altman, Shyamal Anadkat, et al. 2023. Gpt-4 technical report. arXiv preprint arXiv:2303.08774 (2023). [2] Alexandru Agache, Marc Brooker, Andreea Florescu, Alexandra Iordache, Anthony Liguori, Rolf Neugebauer, Phil Piwonka, and Diana-Maria Popa. 2020. Firecracker: Lightweight Virtualization for Serverless Applications. In 17th USENIX Symposium on Networked Systems Design and Implementation (NSDI 20). USENIX Association, 419–434. https://www.usenix.org/conference/nsdi20/presentation/ agache [3] Yash Akhauri, Bryan Lewandowski, Cheng-Hsi Lin, Adrian N Reyes, Grant C Forbes, Arissa Wongpanich, Bangding Yang, Mohamed S Abdelfattah, Sagi Perel, and Xingyou Song. 2025. Performance prediction for large systems via text-totext regression. arXiv preprint arXiv:2506.21718 (2025). [4] Anthropic. 2023. Introducing Claude. https://www.anthropic.com/index/ introducing-claude. Anthropic Blog (2023). Accessed: 2026-04-27. [5] Tom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel M. Ziegler, Jeffrey Wu, Clemens Winter, Christopher Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. 2020. Language Models are Few-Shot Learners. In NeurIPS. [6] Yao Cheng, Jianfeng Chen, Jie Chen, Li Chen, Liyu Chen, Wentao Chen, Zhengyu Chen, Shijie Geng, Aoyan Li, Bo Li, Bowen Li, Linyi Li, Boyi Liu, Jerry Liu, Kaibo Liu, Qi Liu, Shukai Liu, Siyao Liu, Tianyi Liu, Tingkai Liu, Yongfei Liu, Rui Long, Jing Mai, Guanghan Ning, Z. Y. Peng, Kai Shen, Jiahao Su, Jing Su, Tao Sun, Yifan Sun, Yunzhe Tao, Guoyin Wang, Siwei Wang, Xuwu Wang, Yite Wang, Zihan Wang, Jinxiang Xia, Liang Xiang, Xia Xiao, Yongsheng Xiao, Chenguang Xi, Shulin Xin, Jingjing Xu, Shikun Xu, Hongxia Yang, Jack Yang, Yingxiang Yang, Jianbo Yuan, Jun Zhang, Yufeng Zhang, Yuyu Zhang, Shen Zheng, He Zhu, and Ming Zhu. 2024. FullStack Bench: Evaluating LLMs as Full Stack Coders. CoRR abs/2412.00535 (2024). arXiv:2412.00535 doi:10.48550/ARXIV.2412.00535 [7] Catalin Cimpanu. 2019. Microsoft: 70 percent of all security bugs are memory safety issues. ZDNet. https://www.zdnet.com/article/microsoft-70-percent-ofall-security-bugs-are-memory-safety-issues/. [8] Thomas Claburn. 2023. Microsoft is busy rewriting core Windows library code in memory-safe Rust. The Register. https://www.theregister.com/2023/04/27/ microsoft_windows_rust/. [9] Rémi Coulom. 2006. Efficient selectivity and backup operators in Monte-Carlo tree search. In International conference on computers and games. Springer, 72–83.

[10] Cybersecurity and Infrastructure Security Agency (CISA). 2023. The Urgent Need for Memory Safety in Software Products. https://www.cisa.gov/newsevents/news/urgent-need-memory-safety-software-products. Accessed: 202604-30. [11] Mehmet Emre, Peter Boyland, Aesha Parekh, Ryan Schroeder, Kyle Dewey, and Ben Hardekopf. 2023. Aliasing Limits on Translating C to Safe Rust. Proc. ACM Program. Lang. 7, OOPSLA1 (2023), 551–579. doi:10.1145/3586046 [12] Mehmet Emre, Ryan Schroeder, Kyle Dewey, and Ben Hardekopf. 2021. Translating C to safer Rust. Proc. ACM Program. Lang. 5, OOPSLA (2021), 1–29. doi:10.1145/3485498 [13] Hasan Ferit Eniser, Hanliang Zhang, Cristina David, Meng Wang, Maria Christakis, Brandon Paulsen, Joey Dodds, and Daniel Kroening. 2024. Towards Translating Real-World Code with LLMs: A Study of Translating to Rust. CoRR abs/2405.11514 (2024). arXiv:2405.11514 doi:10.48550/ARXIV.2405.11514 [14] Wenqi Fan, Yujuan Ding, Liangbo Ning, Shijie Wang, Hengyun Li, Dawei Yin, Tat-Seng Chua, and Qing Li. 2024. A Survey on RAG Meeting LLMs: Towards Retrieval-Augmented Large Language Models. In KDD. ACM, 6491–6501. [15] Muhammad Farrukh, Smeet Shah, Baris Coskun, and Michalis Polychronakis. 2025. Safetrans: Llm-assisted transpilation from c to rust. arXiv preprint arXiv:2505.10708 (2025). [16] Luo feng hitsz. 2026. Luo-feng-hitsz/TRAVEL: v1.0.0. doi:10.5281/zenodo.21132684 [17] Shuzheng Gao, Xin-Cheng Wen, Cuiyun Gao, Wenxuan Wang, Hongyu Zhang, and Michael R. Lyu. 2023. What Makes Good In-Context Demonstrations for Code Intelligence Tasks with LLMs?. In 38th IEEE/ACM International Conference on Automated Software Engineering, ASE 2023, Luxembourg, September 11-15, 2023. IEEE, 761–773. doi:10.1109/ASE56229.2023.00109 [18] Yifei Gao, Chengpeng Wang, Pengxiang Huang, Xuwei Liu, Mingwei Zheng, and Xiangyu Zhang. 2025. Pr2: Peephole raw pointer rewriting with llms for translating c to safer rust. arXiv preprint arXiv:2505.04852 (2025). [19] Google Project Zero. 2021. Memory Safety and the Prevalence of Exploitable Vulnerabilities. https://googleprojectzero.blogspot.com/2021/02/a-yearof-windows-kernel-exploitation.html. Accessed: 2026-04-30. [20] Daya Guo, Dejian Yang, Haowei Zhang, Junxiao Song, Peiyi Wang, Qihao Zhu, Runxin Xu, Ruoyu Zhang, Shirong Ma, Xiao Bi, et al. 2025. DeepSeek-R1 incentivizes reasoning in LLMs through reinforcement learning. Nature 645, 8081 (2025), 633–638. [21] Jaemin Hong. 2023. Improving Automatic C-to-Rust Translation with Static Analysis. In 45th IEEE/ACM International Conference on Software Engineering: ICSE 2023 Companion Proceedings, Melbourne, Australia, May 14-20, 2023. IEEE, 273–277. doi:10.1109/ICSE-COMPANION58688.2023.00074 [22] Jaemin Hong and Sukyoung Ryu. 2023. Concrat: An Automatic C-to-Rust Lock API Translator for Concurrent Programs. In 45th IEEE/ACM International Conference on Software Engineering, ICSE 2023, Melbourne, Australia, May 14-20, 2023. IEEE, 716–728. doi:10.1109/ICSE48619.2023.00069 [23] Jaemin Hong and Sukyoung Ryu. 2024. To Tag, or Not to Tag: Translating C’s Unions to Rust’s Tagged Unions. In ASE. ACM, 40–52. [24] Jaemin Hong and Sukyoung Ryu. 2025. Forcrat: Automatic I/O API Translation from C to Rust via Origin and Capability Analysis. In 2025 40th IEEE/ACM International Conference on Automated Software Engineering (ASE) (Seoul, Korea, Republic of). IEEE Press, 1541–1552. doi:10.1109/ASE63991.2025.00130 [25] Edward J Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Liang Wang, Weizhu Chen, et al. 2022. Lora: Low-rank adaptation of large language models. Iclr 1, 2 (2022), 3. [26] Binyuan Hui, Jian Yang, Zeyu Cui, Jiaxi Yang, Dayiheng Liu, Lei Zhang, Tianyu Liu, Jiajun Zhang, Bowen Yu, Keming Lu, Kai Dang, Yang Fan, Yichang Zhang, An Yang, Rui Men, Fei Huang, Bo Zheng, Yibo Miao, Shanghaoran Quan, Yunlong Feng, Xingzhang Ren, Xuancheng Ren, Jingren Zhou, and Junyang Lin. 2024. Qwen2.5-Coder Technical Report. arXiv preprint arXiv:2409.12186 (2024). [27] Immunant. 2022. C2Rust. https://github.com/immunant/c2rust. [28] Mohammad Abdullah Matin Khan, M. Saiful Bari, Xuan Do Long, Weishi Wang, Md. Rizwan Parvez, and Shafiq Joty. 2024. XCodeEval: An Execution-based Large Scale Multilingual Multitask Benchmark for Code Understanding, Generation, Translation and Retrieval. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), ACL 2024, Bangkok, Thailand, August 11-16, 2024, Lun-Wei Ku, Andre Martins, and Vivek Srikumar (Eds.). Association for Computational Linguistics, 6766–6805. doi:10. 18653/V1/2024.ACL-LONG.367 [29] Chris Lattner and Vikram S. Adve. 2004. LLVM: A Compilation Framework for Lifelong Program Analysis & Transformation. In 2nd IEEE / ACM International Symposium on Code Generation and Optimization (CGO 2004), 20-24 March 2004, San Jose, CA, USA. IEEE Computer Society, 75–88. doi:10.1109/CGO.2004.1281665 [30] Michael Ling, Yijun Yu, Haitao Wu, Yuan Wang, James R. Cordy, and Ahmed E. Hassan. 2022. In Rust We Trust - A Transpiler from Unsafe C to Safer Rust. In ICSE-Companion. ACM/IEEE, 354–355. [31] LLVM Project. [n. d.]. Clang: A C Language Family Frontend for LLVM. https: //clang.llvm.org/. Accessed: 2025-05-26. [32] Feng Luo, Kexing Ji, Cuiyun Gao, Shuzheng Gao, Jia Feng, Kui Liu, Xin Xia, and Michael Lyu. 2025. Integrating Rules and Semantics for LLM-Based C-to-Rust

Luo et al.

Translation. In Proceedings of the 41st IEEE International Conference on Software Maintenance and Evolution (ICSME). 685–696. doi:10.1109/ICSME64153.2025. 00069 [33] Dakota Mahan, Duy Van Phung, Rafael Rafailov, Chase Blagden, Nathan Lile, Louis Castricato, Jan-Philipp Fränken, Chelsea Finn, and Alon Albalak. 2024. Generative reward models. arXiv preprint arXiv:2410.12832 (2024). [34] Vikram Nitin, Rahul Krishna, Luiz Lemos do Valle, and Baishakhi Ray. 2025. C2SaferRust: Transforming C Projects into Safer Rust with NeuroSymbolic Techniques. CoRR abs/2501.14257 (2025). [35] Vikram Nitin, Rahul Krishna, Luiz Lemos do Valle, and Baishakhi Ray. 2025. C2SaferRust: Transforming C Projects into Safer Rust with NeuroSymbolic Techniques. CoRR abs/2501.14257 (2025). arXiv:2501.14257 doi:10.48550/ARXIV.2501. 14257 [36] OpenAI. 2026. GPT-5.4-mini. https://platform.openai.com. Accessed: 2026-04-30. [37] Adam Paszke, Sam Gross, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killeen, Zeming Lin, Natalia Gimelshein, Luca Antiga, Alban Desmaison, Andreas Kopf, Edward Yang, Zachary DeVito, Martin Raison, Alykhan Tejani, Sasank Chilamkurthy, Benoit Steiner, Lu Fang, Junjie Bai, and Soumith Chintala. 2019. PyTorch: An Imperative Style, High-Performance Deep Learning Library. In Advances in Neural Information Processing Systems, Vol. 32. [38] Christopher D Rosin. 2011. Multi-armed bandits with episode context. Annals of Mathematics and Artificial Intelligence 61, 3 (2011), 203–230. [39] Rust for Linux. 2024. Nova: a Rust-based GPU Driver. https://rust-for-linux. com/nova-gpu-driver. Accessed: 2025-05-19. [40] Guangming Sheng, Chi Zhang, Zilingfeng Ye, Xibin Wu, Wang Zhang, Ru Zhang, Yanghua Peng, Haibin Lin, and Chuan Wu. 2024. HybridFlow: A Flexible and Efficient RLHF Framework. arXiv preprint arXiv: 2409.19256 (2024). [41] Manish Shetty, Naman Jain, Adwait Godbole, Sanjit A. Seshia, and Koushik Sen. 2024. Syzygy: Dual Code-Test C to (safe) Rust Translation using LLMs and Dynamic Analysis. CoRR abs/2412.14234 (2024). [42] Momoko Shiraishi and Takahiro Shinagawa. 2024. Context-aware Code Segmentation for C-to-Rust Translation using Large Language Models. CoRR abs/2409.10506 (2024). [43] David Silver, Aja Huang, Chris J Maddison, Arthur Guez, Laurent Sifre, George Van Den Driessche, Julian Schrittwieser, Ioannis Antonoglou, Veda Panneershelvam, Marc Lanctot, et al. 2016. Mastering the game of Go with deep neural networks and tree search. nature 529, 7587 (2016), 484–489. [44] David Silver, Julian Schrittwieser, Karen Simonyan, Ioannis Antonoglou, Aja Huang, Arthur Guez, Thomas Hubert, Lucas Baker, Matthew Lai, Adrian Bolton, et al. 2017. Mastering the game of go without human knowledge. nature 550, 7676 (2017), 354–359. [45] CodeGemma Team, Heri Zhao, Jeffrey Hui, Joshua Howland, Nam Nguyen, Siqi Zuo, Andrea Hu, Christopher A Choquette-Choo, Jingyue Shen, Joe Kelley, et al. 2024. Codegemma: Open code models based on gemma. arXiv preprint arXiv:2406.11409 (2024). [46] Torvalds, Linus and Linux kernel contributors. 2026. Linux kernel source tree. https://github.com/torvalds/linux. Accessed: 2026-04-27. [47] Jeffrey Vander Stoep and Stephen Hines. 2022. Memory Safe Languages in Android 13. Google Security Blog. https://security.googleblog.com/2022/12/ memory-safe-languages-in-android-13.html. [48] Thomas Wolf, Lysandre Debut, Victor Sanh, Julien Chaumond, Clement Delangue, Anthony Moi, Pierric Cistac, Timothee Rault, Remi Louf, Morgan Funtowicz, Joe Davison, Sam Shleifer, Patrick von Platen, Clara Ma, Yacine Jernite, Julien Plu, Canwen Xu, Teven Le Scao, Sylvain Gugger, Mariama Drame, Quentin Lhoest, and Alexander M. Rush. 2020. Transformers: State-of-the-Art Natural Language Processing. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations. 38–45. [49] Xiafa Wu and Brian Demsky. 2025. GenC2Rust: Towards Generating Generic Rust Code from C . In 2025 IEEE/ACM 47th International Conference on Software Engineering (ICSE). IEEE Computer Society, Los Alamitos, CA, USA, 90–102. doi:10.1109/ICSE55347.2025.00127 [50] An Yang, Anfeng Li, Baosong Yang, Beichen Zhang, Binyuan Hui, Bo Zheng, Bowen Yu, Chang Gao, Chengen Huang, Chenxu Lv, et al. 2025. Qwen3 technical report. arXiv preprint arXiv:2505.09388 (2025). [51] Aidan ZH Yang, Yoshiki Takashima, Brandon Paulsen, Josiah Dodds, and Daniel Kroening. 2024. Vert: Verified equivalent rust transpilation with large language models as few-shot learners. arXiv preprint arXiv:2404.18852 (2024). [52] Guang Yang, Yu Zhou, Xiang Chen, Xiangyu Zhang, Terry Yue Zhuo, and Taolue Chen. 2024. Chain-of-Thought in Neural Code Generation: From and for Lightweight Language Models. IEEE Trans. Softw. Eng. 50, 9 (Sept. 2024), 2437–2457. doi:10.1109/TSE.2024.3440503 [53] Zhen Yang, Fang Liu, Zhongxing Yu, Jacky Wai Keung, Jia Li, Shuo Liu, Yifan Hong, Xiaoxue Ma, Zhi Jin, and Ge Li. 2024. Exploring and Unleashing the Power of Large Language Models in Automated Code Translation. Proc. ACM Softw. Eng. 1, FSE (2024), 1585–1608. doi:10.1145/3660778 [54] Hanliang Zhang, Cristina David, Yijun Yu, and Meng Wang. 2023. Ownership Guided C to Rust Translation. In CAV (3) (Lecture Notes in Computer Science, Vol. 13966). Springer, 459–482.

[55] Hanliang Zhang, Cristina David, Yijun Yu, and Meng Wang. 2023. Ownership Guided C to Rust Translation. In Computer Aided Verification - 35th International Conference, CAV 2023, Paris, France, July 17-22, 2023, Proceedings, Part III (Lecture Notes in Computer Science, Vol. 13966), Constantin Enea and Akash Lal (Eds.). Springer, 459–482. doi:10.1007/978-3-031-37709-9_22 [56] Tianyang Zhou, Haowen Lin, Somesh Jha, Mihai Christodorescu, Kirill Levchenko, and Varun Chandrasekaran. 2025. LLM-Driven Multi-step Translation from C to Rust using Static Analysis. CoRR abs/2503.12511 (2025). arXiv:2503.12511 doi:10.48550/ARXIV.2503.12511

Record · ID 394491 · SHA-256 20db3fb8947ced23
Retrieved via Conceptio — every document is proof-bundled with source, license, and retrieval metadata.