Explaining Ownership, Lifetimes, and Borrow-Checking Errors with Lifetime Deficits in Rust
Through ownership and lifetimes, Rust ensures memory safety and prevents data races while enabling efficient execution. These concepts, however, remain difficult for programmers to master. Although prior research has explored approaches to visualizing ownership and lifetimes, existing tools and their evaluations have paid insufficient attention to visualizing both concepts together and to practical programming tasks. In this study, we propose the concept of lifetime deficits and an algorithm that computes them by leveraging the output of the Polonius borrow checker, where the lifetime deficit of a variable is the range in which the variable must live but which its actual lifetime does not cover. Combining this algorithm with information from the Mid-level Intermediate Representation (MIR), we developed \textsf{RustOwl}, a tool for visualizing ownership, lifetimes, and lifetime deficits within text editors. To evaluate the effectiveness of the tool in facilitating learning, we conducted a controlled experiment with 72 programmers, who answered five questions about ownership and lifetimes in Rust code that we provided. The questions involved identifying the causes of compile errors, debugging deadlocks, and comparing memory usage, all of which are tasks relevant to real-world programming. The results demonstrate that users of \textsf{RustOwl} answered these questions significantly more accurately than users of Aquascope, an existing visualization tool.