-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Ignore parent locals when resolving in local items #112142
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
First of all, I'm not sure this is something that needs to be fixed. |
Assumed this might be something that doesn't necessarily want fixing (but it was small enough that it didn't take much time to try to address). If the consensus will be to not fix it I'll look into possibly adjusting the diagnostics then (as they could probably get some love here). |
I think my position now is basically opposite to what I wrote in #33118 back in 2016. I think we should keep the existing behavior, and also continue supporting "local variable capturing" in macros. The current rules are very simple - there's only one "hard" barrier for all names, "Hard" barrier means that we just stop the lookup once reaching a For example, local variables also cannot be used in constant evaluation contexts, and it is also enforced through soft barriers. The examples listed in #112142 are all relatively esoteric and do not pose a pressing issue. |
As for #33118 (comment) in macros, it's not only actually useful in practice, but it also matches the intuition of names being "resolved at definition site". Right now local variables can be resolved at macro definition site too, similarly to any other names. Inability of using outer local variables from functions can be seen as an "unfortunate implementation limitation" from a certain angle, we just cannot codegen it properly, but in other more dynamic and garbage collected languages it can actually be supported. |
I cases like #33118 (comment) we could try "fortifying" the rules by producing errors instead of silently falling back to creating fresh local variables. E.g.
This "fortification" would need to go through crater testing, of course. EDIT: But even if we cannot fortify it this way it's not a big deal, it's also an esoteric case and it can be left as is. |
That we should definitely keep I think as well (I did not check whether the approach here breaks that which I definitely should have). Anyways, the decision to not pursue this is fine with me, I'll take a look at maybe improving the diagnostics here instead then. |
Closing this as it was decided not to pursue this in the above discussion. |
An attempt at fixing #33118
I do want more tests for this, if there are ideas do tell as I couldn't immediately come up with more interesting cases. I'm mainly worried that there might be certain cases where we get multiple errors now.