Mechanical suggestions for some borrow checker errors

Here is a project (report) I worked on this semester for a program synthesis class I took. Admittedly, it is pretty limited (it doesn’t handle a whole bunch of stuff), but I thought I would share it anyway…

I’m not currently intending on pursuing this further, but I would still be interested in any feedback people have.

EDIT: fixed the link

Report: https://github.com/mark-i-m/rust/blob/paper/paper.pdf

Code (beware the hackyness): https://github.com/mark-i-m/rust/tree/synthesis

Abstract:

Rust is a new systems programming language that aims to allow low-level control and high performance, like C/C++, but with memory safety and data-race-freedom guaranteed statically. Rust accomplishes this using a compiler pass called the borrow checker. Unfortunately, the borrow checker’s compile errors are sometimes difficult to understand. Beginners and advanced users alike may not be sure how to resolve them. In our work, we propose a tool that uses the compiler’s analyses to mechanically produce suggestions for how to resolve lifetime-related errors. To evaluate the usefulness of our tool, we survey lifetime-related errors on Stack Overflow and the Rust Users Forum. We find that our tool is helpful for generating fixes for 2 out of the 30 examples surveyed. For only one example, our tool produced a misleading suggestion. We also identify common areas of problems from the surveyed issue, including over-restrictive constraints, subtle interactions with advanced type system features, and fundamental design flaws in user’s programs. We propose that these may be good areas to focus on improving compiler diagnostics.

5 Likes

Please submit a PR without commented out code, new test cases for the cases you are explicitly handling and having run ./x.py test src/test/ui --stage 1 --bless. AS you know, the review may take a while due to length, but I’d love to see these suggestions merged, other than maybe adding code to block out some of the identified suboptimal cases (namely suggesting giving &self a new lifetime).

The list in the appendix is already incredibly useful and would be nice to cut tickets for each of those cases :smiley:

1 Like

Thanks @ekuber :slight_smile:

The code is far from production-worthy ATM, but I might be able clean it up for minimal cases where the suggestions are good. (That might take me a while to get to though).

I can also open issues for the problems identified in the appendix.

2 Likes

Ooops... I broke the link by accident. It should be fixed now!

Also, for those interested, I have started working on the cleanup needed to try to land this: https://github.com/rust-lang/rust/pull/58281

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.