-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Writing to values after giving up ownership doesn't error #31538
Comments
Why should it error? |
The behavior after data.y = vec![]; // is ok
drop(data.y); // error: use of moved value: `data.y` |
@arielb1 - it's a totally fair question. For me it's about having a mental model that's simple to explain for how ownership works after you've handed off ownership of your data. Like @bluss shows, the current behavior is a mix of errors and non-errors, depending on what you're doing. I think a simpler mental model might be something like "after you hand off ownership, any read or write to the data will error." Currently, it's something more like "after you hand off ownership, any read will fail and any write will appear to succeed but will not update the value you've handed off. Instead, it updates an invisible copy you can not read. Also, any update (eg .push(x) or drop) will fail" |
Taking this example:
Currently, Rust nightly doesn't error on the 'data.x = 2' line, even though we've given up ownership to data. The error does appear if you uncomment the following line and try to do something a little less trivial than assigning to an i32.
Should we treat them the same and warn of any use, whether reading or writing, of any field of a value that we no longer own?
The text was updated successfully, but these errors were encountered: