-
Notifications
You must be signed in to change notification settings - Fork 13.3k
NLL lets borrowck observe drop order for let (a, b);
#51036
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
Comments
This probably needs to be brought to the attention of the lang team (at least...) (but i'm not nominating it for discussion yet because i want to ruminate on the matter a bit.) |
The main argument I can think of in favor of the old static semantics is that some people may prefer developers to be forced to write However, my personal suspicion is that this change to the static semantics will solve more usability problems for our users than it "causes." |
I don't think we are going to fix this. It seems hard and anyway changing the evaluation order here would be...unadvisable imo? I'll nominate for lang time but I'm also going to go ahead and FCP to close. |
@bors fcp close The old AST based borrow check was not "aware" of the drop order for variables within a single let (a, b) = ...
The new borrow checker seems things after lowering and hence it naturally knows the order in which I think this is OK. We are not going to change that ordering anyway -- see also RFC 1857. |
Putting on the Release milestone. |
@rfcbot fcp close |
@rfcbot fcp close The old AST based borrow check was not "aware" of the drop order for variables within a single let (a, b) = ...
The new borrow checker seems things after lowering and hence it naturally knows the order in which I think this is OK. We are not going to change that ordering anyway -- see also RFC 1857. |
Team member @nikomatsakis has proposed to close this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to close, as per the review above, is now complete. |
NLL is built on MIR-borrowck. MIR-borrowck operates on the control-flow graph encoded in the MIR.
We didn't (and still do not) want to let borrowck depend on details of how we choose to codegen the MIR from a given AST (in particular for
match
expressions), and so we put some effort into trying to obscure those details from the view of MIR-borrowck.But there was a case that we (potentially) overlooked: MIR encodes the order in which the variables
a
andb
are dropped inlet (a, b);
, and now NLL/MIR-borrowck takes advantage of that knowledge when checking code.match
). So ths arguably does not fall into the same bucket as the previous motivation forFalseEdges
in the MIR.In particular, in the following example (adapted from ui/dropck-eyepatch.rs):
Using AST-borrowck (by commenting out the
#![feature(nll)]
at the top) emits the following errors:Using NLL compiles successfully, because NLL/MIR-borrowck only sees a more precise model of the relative drop order of the variables declared via
let (c, dt, dr);
, and takes advantage of it.The question is: Are we okay with this side-effect of NLL?
I don't think it was explicitly documented as an intended effect.
However, I think the fact that we used to use an imprecise model for the drop-order in
let (c, dt, dr);
previously was more due to the weaknesses of AST-borrowck. Under NLL, we can encode the more precise relationships needed to check the borrowing behavior in this program and validate that it is safe to letdt
anddr
hold references toc
here.The text was updated successfully, but these errors were encountered: