Skip to content

Clarify terminology around destructors and dropping #1078

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

Open
ehuss opened this issue Jul 26, 2021 · 2 comments
Open

Clarify terminology around destructors and dropping #1078

ehuss opened this issue Jul 26, 2021 · 2 comments
Labels
A-destructors Area: destructors, dropping Language Cleanup Improvements to existing language which is correct but not clear, or missing examples, or the like.

Comments

@ehuss
Copy link
Contributor

ehuss commented Jul 26, 2021

In #1037 a question came up about the exact wording around the introduction of the destructors chapter which says

When an initialized variable or temporary goes out of scope its destructor is run, or it is dropped.

The PR author interpreted the phrase dropped meaning a synonym for running the destructor. But I read it as two separate concepts:

  • When any value goes out of scope, it is "dropped".
  • If the value has a destructor, that destructor is run.

I don't think "dropping" and "running destructors" can be used interchangeably because not all values have a destructor. However, I am uncertain if that is correct, or if that is the best way to document these concepts. Either way, it would be good to clarify that a little.

@ehuss ehuss added A-destructors Area: destructors, dropping Language Cleanup Improvements to existing language which is correct but not clear, or missing examples, or the like. labels Jul 26, 2021
@crlf0710
Copy link
Member

crlf0710 commented Aug 2, 2021

I think all values have destructors, but (in C++ term) not all destructors are non-trivial. On the other hand, std::mem::needs_drop's naming is really a little confusing...

@botahamec
Copy link
Contributor

According to the documentation for the Drop trait, "[Copy types] cannot have destructors", so they can't possibly be synonyms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-destructors Area: destructors, dropping Language Cleanup Improvements to existing language which is correct but not clear, or missing examples, or the like.
Projects
None yet
Development

No branches or pull requests

3 participants