-
Notifications
You must be signed in to change notification settings - Fork 13.3k
NLL fails to remind users that locals in same scope are dropped in reverse declaration order #51195
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
The importance of doing this (and doing it well) may grow in the face of the potential change to the static semantics described in #51036 |
@pnkfelix |
@estebank yes, |
So, @spastorino and I have been talking a bit about this in Zulip. The actual NLL error message is in some ways better than the AST one. Notably, it includes the crucial bit of info that the final use of the variable is in the destructor for
that said, it would be that much better if it also included the note about the relative order of variables being significant. The question is when to print such a thing. As I wrote on Zulip, I think we want to trigger the message under two conditions: (1) the last use is when another local variable is dropped We find about Condition (1) in the function rust/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs Lines 56 to 89 in 2a00629
In that same function, we have access to some information about the borrow in the
The
so we can check that this |
Actually I was probably thinking about this wrong. Instead of looking at what path was borrowed, I think we want to consider the point of the error: In particular, if the point of the error is a |
That means detecting when we are reporting an error due to this call (or the one for rust/src/librustc_mir/borrow_check/mod.rs Lines 501 to 509 in 2a00629
So specifically looking for rust/src/librustc_mir/borrow_check/mod.rs Line 505 in 2a00629
|
Comment from Zulip, recording for posterity: Recall that the basic structure of the "error reporting" phase of the borrow check is like this:
Currently, if there is a loan of that variable What I am saying is that in precisely these conditions, where the current statement is a
It seems like precisely here is where the relative order of variables is relevant. |
… r=nikomatsakis Diagnostic suggest drop in reverse Closes #51195
Looking at a case like E0597.rs, we can see that the AST-borrowck includes the note:
rust/src/test/ui/error-codes/E0597.stderr
Line 10 in 2e104a7
while NLL has no reminder about the drop order for a pair of locals declared in the same lexical scope.
But anyway, the point is that NLL is failing to say anything at all on the matter, which is probably not ideal for Rust's target audience.
The text was updated successfully, but these errors were encountered: