Introduction
Code translation—the process of migrating a software project from one programming language to another—remains a labor-intensive challenge for developers. While Large Language Models (LLMs) have demonstrated impressive capabilities in translating between high-level languages like Java and Python, targeting Rust presents unique difficulties. Rust’s stringent memory safety guarantees, ownership model, and complex syntax often act as a barrier for automated translation tools.
Existing benchmarks for code translation typically fall into two extremes: they either focus on isolated, dependency-free functions that fail to capture real-world complexity, or they attempt full-repository migration where models fail so comprehensively that diagnostic insights are lost. To bridge this gap, researchers have introduced RustRepoTrans, a benchmark designed to evaluate LLMs on "incremental translation"—the migration of specific modules within an existing repository context.
The RustRepoTrans Benchmark
RustRepoTrans addresses the "context gap" by requiring models to understand repository-level dependencies, such as custom data types, cross-module function calls, and variable resolutions. The benchmark consists of 375 translation tasks derived from real-world GitHub projects that were manually rewritten from C, Java, or Python into Rust.
The construction of the dataset involved a rigorous pipeline:
- Functionally Equivalent Pair Extraction: Using the BM25 algorithm to identify candidate pairs across language versions, followed by GPT-4o filtering and expert manual verification.
- Dependency Mapping: Static analysis was employed to extract three critical dependency types for each target Rust function: functions, variables, and data types.
- Unit Testing: Each task is accompanied by unit tests providing over 90% code coverage to ensure functional correctness.
Experimental Results and Model Performance
The researchers evaluated seven state-of-the-art LLMs, including DeepSeek-R1, Claude-3.5-Sonnet, and GPT-4. Performance was measured using Pass@1 (success on the first attempt) and DSR@1 (success after one round of compiler-feedback-driven self-debugging).
As shown in the results, DeepSeek-R1 leads the field with a 51.5% Pass@1 and 62.1% DSR@1. Claude-3.5-Sonnet also performed strongly, demonstrating the most significant relative improvement (29.9%) when provided with compiler feedback. A key finding is the "Context Penalty": even the best models experience a sharp decline in performance when moving from isolated tasks to repository-level tasks. For instance, DeepSeek-R1’s success rate dropped from 73.7% in a dependency-free environment to 51.5% on RustRepoTrans.
Analysis of Failure Modes
The benchmark highlights that the Rust compiler is an exceptionally rigorous judge. Approximately 92.3% of all failures were compilation errors rather than runtime logic errors. This underscores Rust's ability to catch hallucinations—such as incorrect type usage or ownership violations—at the build stage.
The primary source of these errors (73.9%) was a failure to navigate the differences between the source and target languages' repository structures. Specifically, resolving functions and variables across file boundaries accounted for 67.6% of failures. This suggests that while models may "know" Rust syntax, they struggle with the "interconnectedness" of a project.
Conclusion and Future Directions
RustRepoTrans reveals that repository-level context is the primary hurdle for automated code translation into Rust. While "reasoning" models like DeepSeek-R1 show superior noise robustness and the ability to produce idiomatic code, there is still a significant performance gap to close.
Future work should focus on enhancing LLMs' ability to reason across file boundaries and improving the mapping of complex types between languages. Integrating LLMs with external static analysis tools may also provide a path toward "pre-verifying" code before it ever reaches the compiler, further streamlining the migration process.
Summary updated