reference icon indicating copy to clipboard operation
reference copied to clipboard

Clarify terminology around destructors and dropping

Open ehuss opened this issue 4 years ago • 2 comments

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 avatar Jul 26 '21 20:07 ehuss

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...

crlf0710 avatar Aug 02 '21 17:08 crlf0710

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

botahamec avatar May 07 '22 19:05 botahamec