-
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
std::ops::Drop documentation focuses on scope, ignores other causes of drops #36073
Comments
I feel like scopes are still the best way to model the intuition about drops, but it is important to understand that scopes used for drop generation aren’t exactly the lexical scopes which you have in the source file. Most notably drop scopes may overlap in various ways in which the lexical scopes cannot. Similarly, each let binding introduces a scope, which is distinct from any lexical scope you have. (Re-)assignments are best considered as a sugar for |
What exactly is a "scope", then? An arbitrary execution path in the CFG? I can't see them being anything less, since all the various operations that cause early drops may be conditional or in loops. And I find it very strange to "desugar" a primitive language construct such as assignment to a combination of various API calls. I understand it's meant for "intuitive" understanding, but even so it sounds strange and possibly counter-productive for people confused about drop placement. |
I adjusted the title to make it more clear this is talking about documentation, rather than the operation of destructors in general. |
doc team triage: p-medium |
Triage: no changes, though with NLL, referring to it as a scope will become even more confusing, making this a higher priority. |
Fixes rust-lang#36073 Drop's docs were not great, and as mentioned in rust-lang#36073, focused too much on scope. I've re-done them a bit, using the same examples, and making it clear that scope is not the only thing that causes destructors to run.
There was some confusion in #rust over when values are dropped. It was pointed out that the
std::ops::Drop
documentation only says drop is called if "a value goes out of scope", which is inaccurate:I don't know how to best phrase it, but focusing only on scopes is evidently a good way to confuse people.
The text was updated successfully, but these errors were encountered: