-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Rewrite nomicon references section #27911
Comments
It has been argued that the references section should be written in terms of lvalue paths. I believe this is what the borrow checker reasons in terms of, and is at very least a concrete concept. However this section does not want to simply model how the borrow checker thinks -- the entire point is that there needs to be a more fundamental model that the borrow checker models a subset of, but is fundamentally unable to model all of. This is the model unsafe code should be written against, and that the borrow checker can grow into if improved (e.g. nonlexical borrows). |
CC @RalfJung and co who are working on formally modeling Rust's semantics. |
Indeed, we'll have some fun figuring this out ;-) Speaking of which, "A reference cannot outlive its referent" is already something that's not actually enforced in my model. It's only when you use a reference that you have to prove that the referent is still alive, by showing that the lifetime of the reference is still active. As long as you don't use the reference, the model doesn't care whether it is valid. I should also mention that "path" is not a thing in my formal model. I don't even have a stack. It's all about owning locations, or knowing the protocols that some locations are currently subject to. (Like, a shared borrow to a basic datatype follows the protocol that everybody can read it, and that multiple reads are guaranteed to deliver the same result. A mutable borrow to a basic datatype has the protocol that you can temporarily exchange your borrow for actual ownership of the referent, but until you change this back, it is impossible for the lifetime of the borrow to end.) The challenge will be to translate these protocols, and the even more implicit notions of separation/disjointness, back to something that makes sense when looking at surface Rust code... |
This was essentially what the whole I think the "path" description in the current document is a bit of a dead end for what the book is ultimately trying to do -- describe the constraints on unsafe code. I do think that a more precise version of the path explanation would be a good way to explain borrow checking, though. |
I assume this is the correct issue to add this question to. I've discovered through some experimentation and by reading #10488 that let _ = Iron::new(hello_world).http("localhost:3000").unwrap(); for example causes the destructor to be run immediately (i.e. the end of the statement) and so joins the thread and blocks further execution, but let _ = &Iron::new(hello_world).http("localhost:3000").unwrap(); extends the lifetime to the enclosing block. I can understand that let _listen = Iron::new(hello_world).http("localhost:3000").unwrap(); extends the lifetime to the enclosing block because that is the scope of the variable |
Interesting! @eddyb any thoughts on this? |
On Mon, Nov 09, 2015 at 06:05:20PM -0800, Parakleta wrote:
Yes, these are all different. It's kind of the intersection of two So something like let foo;
{
let temp = <expr>;
foo = temp.0;
} Note that So in terms of your examples:
Meanwhile, orthogonally: It's possible that the lifetime of the temporary we create when doing |
The discussion in #10488 for the distinction between |
On Tue, Nov 10, 2015 at 12:39:02PM -0800, Parakleta wrote:
No. The rules are more subtle than that. Temporaries usually live Hence, the following temporaries will last until end of block:
But (under current rules) this would not:
See http://doc.rust-lang.org/reference.html#temporary-lifetimes for |
So the Does this mean that |
@Parakleta |
Thanks, I just noticed the text "The compiler uses simple syntactic rules to decide" in the reference manual. This all seems a bit fragile, considering that the decision is made on Syntax rather than Semantics. For example, if I have |
On Thu, Nov 12, 2015 at 04:06:03PM -0800, Parakleta wrote:
It is true that you have to know the contents of the macro. However, |
Moving this to rust-lang/nomicon#7 |
https://doc.rust-lang.org/nightly/nomicon/references.html
This involves solving the incredibly difficult question of "what on earth are Rust's True Pointer Aliasing Rules".
CC @aturon @arielb1 @nikomatsakis @pnkfelix @sunfishcode
The text was updated successfully, but these errors were encountered: