arXiv:2611.06319cs.PLNov 2026

Manuscript Offprint

arXiv:2611.06319

Verified Implementation of the Next-gen Borrow Checking Algorithm for Rust via Abstract Interpretation

Jinhua Wu, Yuting Wang, Zhemin Chen

JINHUA WU, Shanghai Jiao Tong University, China

YUTING WANG*, Shanghai Jiao Tong University, China

ZHEMIN CHEN, Nanjing University, China

Borrow checking is a central mechanism for Rust to ensure temporal memory safety. Its correctness is based on the intuition that the Aliasing XOR Mutability discipline guarantees that programs without borrow errors inherently could not access invalid references (i.e., pointers). However, existing work on formalizing borrow checking treats it either as a component of type systems or as symbolic execution describing resource transfer. None provides a direct explanation of the correctness of borrow checking algorithms such as Non-Lexical Lifetimes (NLL) or Polonius in the official Rust compiler that function more like static pointer analysis.

We take a first step toward solving this problem by formalizing Polonius, the next-generation borrow-checking algorithm for the Rust compiler, on a core subset of Rust. We prove its correctness by showing that any program accepted by Polonius does not access invalid references at runtime. The key observation is that, when borrow checking is performed lazily, Polonius could be treated as a forward abstract interpretation on abstract domains recording pointer aliasing (borrowing) relations. By providing a concrete semantics that formally describes the Aliasing XOR Mutability discipline, we prove the soundness of this abstract interpretation, from which we derive memory safety of checked programs. This formulation of Polonius is implemented and formally verified in the abstract interpretation framework of CompCert. The correctness proofs are generated by an agentic AI under human guidance using paper proofs as proof outline. To the best of our knowledge, this is the first comprehensive formalization and verification of a borrow checking algorithm as manifested in the Rust compiler.

1 Introduction

Memory safety problems caused by accessing invalid pointers or references are the most common vulnerabilities in software [45, 48]. To mitigate those problems, memory safe languages are increasingly favored over unsafe ones (e.g., C/C++). Among them the most prominent is Rust [47]. Rust employs a strong type system and ownership semantics to ensure both temporal (e.g., no dereference of dangling pointers) and spatial memory safety (e.g., no out-of-bounds access). For the former, the central idea is to enforce the so-called Aliasing XOR Mutability discipline (i.e., there can be either only one mutable reference or multiple shared references to a value at any execution point) to rule out potentially unsafe uses of references. We shall abbreviate this discipline as AXM.

Borrow checking is the static analysis for Rust to ensure memory safety by enforcing AXM. Consider the following Rust code snippet which manipulates heap memory owned by Box structures:

1 let mut v = Box::new(1);
2 let mut r = &mut *v;
3 v = Box::new(2); // error: cannot assign to v because it is borrowed
4 println!("{}", *r); // borrow later used here

If the code is compiled and executed without any safety checking, a use-after-free error occurs at line 4 because the heap memory originally bound to v has been deallocated after line 3, making r a dangling reference. The Rust compiler rejects this program as its borrow checker detects a violation of AXM at line 3: *v is mutably borrowed by r until line 4 and therefore its prefixes (i.e., v and *v)

*Corresponding author

Authors' Contact Information: Jinhua Wu, John Hopcroft Center for Computer Science, School of Electronic Information and Electrical Engineering, Shanghai Jiao Tong University, China, jinhua.wu@sjtu.edu.cn; Yuting Wang, John Hopcroft Center for Computer Science, School of Electronic Information and Electrical Engineering, Shanghai Jiao Tong University, China, yuting.wang@sjtu.edu.cn; Zhemin Chen, Software Institute, Nanjing University, China, zheminchen@gmail.nju.edu.cn>.

Jinhua Wu, Yuting Wang, and Zhemin Chen

2

1 let mut v = Box::new(1); // NLL | Polonius
2 let mut x: &'x mut i32 = &mut *v; // *v live | 'x:{*v}
3 let mut y: &'y mut i32 = &mut *x; // *v,*x live | 'x:{*v}, 'y:{*v,*x}
4 *x = 2; // Error: cannot access *x because it is borrowed
5 *y = 3; // borrow later used here

Fig. 1. An example to illustrate NLL and Polonius

could not be mutated before line 4. In summary, borrow checking statically examines the possible violations of AXM, thereby preventing any potential access to invalid references at runtime.

In the official compiler of Rust, i.e., rustc, borrow checking is implemented as an algorithm that solves memory safety constraints and checks if the solution violates AXM [25, 44]. To deal with complicated programming language features in Rust such as storing references in data structures, reborrowing of existing references, passing and returning references for function calls, etc., borrow checking algorithms are highly sophisticated and continuously evolving. Two versions of borrow checkers are currently implemented in rustc: Non-Lexical Lifetimes (NLL) [44] and Polonius [25, 41]. The former has been the default borrow checker for a long time and the latter is an experimental one that employs a more accurate borrow analysis and will replace NLL in the near future.

In both NLL and Polonius, the key to ensuring that only valid references are accessed lies in analyzing which places (Rust's terminology for memory locations holding values, similar to *l-values in C/C++) may be borrowed at each program point, based on which violation of AXM is then detected. This is made possible by annotating types of references with generic variables called regions. Consider the example in Fig. 1 where 'x and 'y are regions in the types of references x and y, respectively. In NLL, a region is interpreted as lifetime, i.e., a span of code over which a reference and its borrowed places remain alive (i.e., they will be used later). For instance, the lifetime denoted by 'x spans over lines 2-4. At line 3, a reborrow of *v by y happens through dereferencing x. The lifetime of 'y spans over lines 3-5, making its borrowed place *x alive up to line 5. Because *x is still mutably borrowed at line 4, it cannot be assigned, resulting in a borrow checking error. By contrast, Polonius interprets a region r as an abstract pointer variable that stores a set s of borrowed places, which we shall write as r : s. At any point of execution, this set (over-)approximates all the possible places the reference variable could borrow. For example, at line 2, 'x : {*v} indicates that x may borrow *v as 'x is the abstract pointer representing x. At line 3, the places borrowed by y are additionally recorded in 'y : {*v, *x}. Using this borrowing information, Polonius checks if, at any point of execution, the instruction being executed violates AXM w.r.t. borrowed places contained in live regions. For example, because y (hence its region 'y) is alive up to line 5 and it borrows *x, assignment to *x at line 4 violates AXM. As we can see, Polonius captures the borrow relations for individual references at all points of execution, and is therefore more accurate than NLL which only records live places as a whole. This enables Polonius to accept a wider range of safe programs, a main reason that it is chosen as the next-gen borrow checking algorithm for rustc.¹

Considering the central role borrow checking algorithms play in the Rust compiler, it is highly desirable to formally verify their correctness. However, despite the impressive efforts the PL community puts into researching Rust, there is not yet successful attempt along this line. Instead, existing work formalizes borrow checking either as an ownership type system for Rust (e.g., RustBelt [14], Oxide [50], Pearce [31]), or as symbolic execution with resource transfers (e.g., Aeneas [10]), which deviates from the region-based static analysis adopted by NLL or Polonius. Verifying the correctness of borrow checking algorithms in the Rust compiler is still an open problem.

¹Fig. 1 also illustrates the conservative nature of borrow checkers. Although line 4 does not actually cause a memory error, the program is still rejected by rustc. Inaccuracy is the price we pay for the ability to statically check memory safety.

Verified Implementation of the Next-gen Borrow Checking Algorithm for Rust via Abstract Interpretation

3

In this paper, we investigate a solution to this open problem by developing a verified implementation of Polonius. Before delving into the solution, we first explain why the problem is difficult.

Challenge 1: Formalization of Borrow Checking Algorithms Amenable to Verification. To formally prove borrow checkers correct, we must first give them a formal description in theorem provers. However, this is difficult because of the ad-hoc and complex implementation of borrow checkers. In rustc, NLL and Polonius employ sophisticated constraint generation and solving techniques [25, 44, 46] which are entangled with other kinds of safety checking such as type checking, liveness checking, and module-level analysis. Although there is documentation like RFCs, blog posts, and even a rule-based formulation in Datalog (at least partially for Polonius [36]), it is not clear at all if there exists a formulation of NLL or Polonius amenable to verification.

Challenge 2: Semantics Suitable for Verifying Borrow Checking Algorithms. Borrow checkers work on MIR, an intermediate language represented as control-flow graphs (CFG). For verification, we need to give this IR a formal semantics that faithfully describes when memory errors occur at runtime, so that we can prove their absence under successful borrow checking. More importantly, we need to connect this low-level semantics with a more higher-level semantics that captures the essence of borrow checkers. For Polonius, this essence is its alias analysis nature. For example, the relation between borrowed places 'y : {*v, *x} in Fig. 1 actually implies that *v, *x and *y are aliases of each other. It is exactly by analyzing this alias information that Polonius is able to enforce AXM, hence to guarantee memory safety.

Challenge 3: Proving the Correctness of Borrow Checking Algorithms. Intuitively, borrow checkers in rustc are correct, i.e., if they could not detect any borrow error, then the program does not contain any uses of invalid references. However, to formally prove this intuition is a significant challenge. First and foremost, the actual form of AXM is more complicated because of pointer assignments, which is another term for reborrowing. For example, the reborrowing at line 3 in Fig. 1 is actually desugared from the following pointer assignment by rustc [42]:

1 let mut y: &'y mut i32 = x;

In real-world software, pointer assignments (hence reborrowing) are ubiquitous. They create multiple mutable references to values, which easily breaks AXM. Therefore, Rust actually allows multiple mutable references to coexist provided that their uses are well-nested like a stack. For example, if we switch lines 4 and 5 in Fig. 1, then the modified program passes borrow checking because x and y are used in a first-defined-last-used fashion. As a result, the more complex stacked AXM discipline, i.e., that only well-nested memory accesses according to the stack ordering are allowed, must be taken into account when proving correctness.

Second, pointer manipulations in real-world code further complicate the proof. For example, the assignment between nested references (i.e., pointers to pointers) causes aliases of locations to merge; reference arguments in functions and struct fields could be annotated with generic regions called lifetime parameters which extend the lifetime of references indefinitely. It is unclear how accesses to references could be proven safe in presence of these complications.

Finally, our ultimate goal is to derive memory safety from borrow checking. Although there is the folklore that AXM implies absence of accessing invalid references, it is not clear what exactly is a formal definition of this implication relation. Even if we know this formal definition, proving it holds for stacked AXM under complicated pointer manipulation is still a huge undertaking.

References (18)