Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPotential generalization of destructing struct destructuring #11855
Comments
glaebhoerl
referenced this issue
Feb 20, 2014
Merged
Fix generic Drop impls with trait bounds. #12403
This comment has been minimized.
This comment has been minimized.
|
cc me |
This comment has been minimized.
This comment has been minimized.
|
(Though, this probably should be written up as an RFC. Or perhaps first work out the kinks on http://discuss.rust-lang.org, which is how I found this in the first place...) |
This comment has been minimized.
This comment has been minimized.
|
Probably, but probably not now. It'd only be postponed anyways. |
This comment has been minimized.
This comment has been minimized.
|
This should probably be moved to the RFCs repo? |
steveklabnik
referenced this issue
Jan 23, 2015
Open
Potential generalization of destructing struct destructuring #713
steveklabnik
closed this
Jan 23, 2015
This comment has been minimized.
This comment has been minimized.
|
Your wish is my command :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
glaebhoerl commentedJan 27, 2014
Currently structs with destructors are (sensibly) not allowed to be move-destructured (#3147), because then when their destructor runs, it would access deinitialized values.
This could potentially be generalized if we recognize that a destructor, in other words drop glue, is not an indivisible thing. It consists of the
Dropimpl for the struct itself, and the destructors for each of its fields. Therefore if we write:when the destructuring happens we could run the
Dropimpl forS, but not the drop glue forAandB. Those are then moved out, and their destructors will run later, whenever they go out of scope.I believe this is sound:
Drop::drop()takes&mut self, so it can mutate the components ofSbut not deinitialize them. If we broaden our considerations tounsafecode, then if the fields of a structShave destructors themselves, then theDropimpl forSmust, even today, leave them in a valid state, because those destructors will then access it. It is only cases where the fields ofSdo not have their own destructors, and theDropimpl forSusesunsafecode to put them in an invalid state, which would become dangerous, and we would have to be very careful about.We'd obviously have to think about whether we actually want this (I haven't thought of any use cases yet), but as a theoretical possibility, I think it checks out.