-
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
Generalize moves to allow moves out of any owned content #4384
Comments
Presumably the problem here is how borrow checker treats moves out of fields contained in rvalues. But that code needs to be somewhat re-worked in general. |
Oh, actually, this is not specific to rvalues really. It's just a generally unnecessary limitation of borrowck. |
I'm confused why this isn't specific to rvalues. Isn't This seems to me like a legal special case because it could be syntax sugar for |
I am editing the title of this issue and expanding it. We should allow moves out of arbitrary owned content. Most of the system is setup for this already, I think the only problem is that borrow check flags such moves as illegal. (But there might be trans work needed to) Examples of things that ought to work but do not:
In some cases these can be expressed today using match statements. I see no reason for match statements to be more expressive than other kinds of expressions; moreover, they do not allow Currently, the moves code and liveness analysis will allow such moves. They would cause the local variables |
@bblum your example is illegal today but I don't see any good reason for that restriction. |
assigning bug; change assignment if you disagree |
Some FIXMEs related to bits of code that will have to be adjusted. |
…terns into borrow checker and generalize what moves are allowed. Fixes a nasty bug or two in the pattern move checking code. Unifies dataflow code used for initialization and other things. First step towards once fns. Everybody wins. Fixes rust-lang#4384. Fixes rust-lang#4715. cc once fns (rust-lang#2202), optimizing local moves (rust-lang#5016).
Move the computation of what data is moved out of `liveness` and into `borrowck`. The resulting code is cleaner, since before we had a split distribution of responsibilities, and also this avoids having multiple implementations of the dataflow code. Liveness is still used to report warnings about useless writes. This will go away when we get the control-flow graph code landed (working on that). Also adds borrow checker documentation. Fixes #4384. Required to support once fns and to properly fix closures (#2202). First step to generalize our treatment of moves somewhat as well.
The example program compiles and runs now. Can this be closed? |
Yes, fixed. |
This program should be legal
But it yields:
The text was updated successfully, but these errors were encountered: