Ownership and borrowing

I would like to understand how Rust implements ownership and borrowing in its compiler. I would appreciate any reference to the relevant folders in the implementation and explanations/papers describing what these folders implement.

To clarify, I already read about the semantics of ownership and borrowing rules. However, I'm interested in the techniques used to implement the corresponding checks.


I see there is an RFC quoted at the implementation at BorrowCheck/mod.rs. A link to that RFC would also be helpful.

Here is a good place to start: https://rustc-dev-guide.rust-lang.org/borrow_check.html

1 Like

Thank you! How should I proceed to read the source of the main entry point, i.e.:


I mean can it be done from the link itself?

It's also worthwhile to read these blog posts by Niko Matsakis (lead of the lang and compiler team). The relevant posts are all under the headline "NLL" in this list (unfortunately his blog doesn't let you link to just the category):


Some of the posts (those that refer to polonius) are about a new method of implementation that rustc will probably use someday in the future, but currently doesn't.

1 Like

@rjraya Sorry, I know this is a bit late, but I would recommend reading the rustc dev guide chapter and then source code you linked. The code makes more sense if you read the chapter first (at least, it did to me)

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