-
Notifications
You must be signed in to change notification settings - Fork 59
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
Local let binding does not prevent mutation #1596
Comments
That is a good example of why I think we should seriously reconsider the idea of allowing escape through local let bindings. The reason why the access checker doesn't complain is that there is no other use of
IMO there is no formal argument for accepting the function above but not the one from the original post. To me, it means that if we special-case access promotion so that we can only go from |
Could a solution be to require the user to declare intent with a different keyword?
|
There are 4 introducers for binding (5 if we count
The purpose of access promotion is to interpret IMO the right way to write OP's function is as follows:
And the right way to write the function in my response is:
|
On Sep 17, 2024, at 11:44 PM, Dimi Racordon ***@***.***> wrote:
there is no formal argument for accepting the function above but not the one from the original post
I think that depends entirely on how you describe the system. The principle that an object can move at its point of last use is enough to justify it. I suppose one could misinterpret that phrasing as meaning the object can move into a synthesized mutable binding with the same name as the original, but that would be perverse IMO.
|
This seems very understandable to me -- I can move out of a local let-binding when the compiler knows that it refers to a lifetime-extended temporary (with apologies for my C++ terminology) So is the problem that the compiler is not enforcing the immutability of |
|
It cannot, because |
To put it differently, it could be reduced to just |
Thank you for the clarification. |
The example given in the documentation is
However, this code currently compiles without error
The text was updated successfully, but these errors were encountered: