Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F permission #214

Open
alexdaguy opened this issue Oct 6, 2024 · 1 comment
Open

F permission #214

alexdaguy opened this issue Oct 6, 2024 · 1 comment

Comments

@alexdaguy
Copy link

I am very much enjoying reading the Chapter 4.2 of this book with how the R, W and O permissions work, but I was sad to see the section at the end with the F permission where it sort of glosses over it. From reading that part my understanding of the F permission is limited to that it is required to use input/output reference in an expression, it's a separate mechanism from the prior R, W, O that is used for references inside the body, and that it might have something to do with lifetimes. I am shown some examples of the F permission in action but none demonstrate to me how it is determined whether something has the F permission or not, unlike RWO for which I have some idea of how the compiler would step through the code and decide how to enable/disable the permissions along the way.

I think including an explanation of this would really be a step forward allowing readers to understand in depth how Rust exactly works, which would be immensely valuable. Currently the official Rust Book kind of just handwaves the concepts of ownership and borrowing, such that a reader of that book doesn't actually find out how the language works, cannot build a mathematical model of the language in their head and therefore cannot look at a piece of code and determine if it would compile. But I think this book really has the potential to do that as it is able to walk you through the borrow checker logic.

Again, thank you for this book, it is giving me the chance to understand Rust.

@willcrichton
Copy link
Collaborator

The short explanation: say you have an expression that has an actual type &'a T and an expected type &'b T for some lifetimes 'a and 'b. The expression needs the F permission if 'b is a lifetime that escapes the current function. The expression has the F permission if 'a outlives 'b, i.e. 'a: 'b is true.

I agree that the current explanation in the book is too cursory. I'm also not fully certain that the F permission is the ideal way to represent these valid or invalid flows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants