-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
MIR-borrowck: immutable unique closure upvars can be mutated #46023
Comments
There are two ways to fix this. We can update the |
UPDATE: You can probably ignore these instructions. I think we will use the simpler approach described below for now.
Lines 122 to 124 in aabfed5
Lines 1326 to 1327 in aabfed5
|
Having another kind of "semi-secret" reference in the type-system that is used almost nowhere scares me - e.g., upvar OIBITs can be implemented for I would prefer a spot change to permission checking - at least error reporting already has to detect dereferences of upvars, so it can check whether an upvar is supposed to be immutable, and in that case treat it as immutable. |
@arielb1 I'm of two minds. On the one hand, I think that trying to make the type system more honest would reveal a lot of interesting things, and I still think it's something we ought to do at some point, precisely because it will reveal interactions like the OIBIT one that you mentioned, which I think are important for us to understand and work through. However, now may not be that time. That said, certainly, a spot change will be easier. =) If we want to do that, this is what I think we have to do: We need to extend the Then we have to alter MIR construction to update the field for its new type. This is the code in question: rust/src/librustc_mir/build/mod.rs Lines 430 to 437 in 5f1c37a
It should be fairly easy to extract the mode from there, it's found in the Finally, we have to modify the rust/src/librustc_mir/borrow_check.rs Lines 989 to 997 in 5f1c37a
It needs to also have a check whether this is the field of an upvar. The helper function introduced in #46087 would be most useful here, so maybe we wait for that to land or else build on it. Then you could do |
My model used to be that immutable locals are basically a lint - i.e. we already know they have no soundness implication, instead we just check them for the user's convenience, and for that we do not need to add another type. A closure captures an immutable local by I just think that adding a new kind of reference to the type-system itself would raise questions, and if we are actually adding new kinds of references, it's for the better if they are user-visible instead of being a hidden compiler feature. |
I've started work on this locally, will open a WIP PR when I've got something. |
MIR-borrowck: immutable unique closure upvars can be mutated Fixes #46023 and #46160 (see [this comment](#46236 (comment))).
MIR borrowck allows for immutable unique closure upvars to be mutated, e.g.
The text was updated successfully, but these errors were encountered: