1
lorentz
225d

Hot take: Rust doesn't go far enough with explicit clone; dropping any type that isn't trivially copiable should also be explicit. I don't mean that it should be leaked if you don't delete it, I mean that the compiler should force you to explicitly say

"I am done with this object, anything that had to know about it has already been notified and either there isn't a single last point of use or it isn't a clone, therefore dropping is justified."

This is the whole meaning of dropping a complex object. I think that this is far too strong a statement to imply in bulk for every value in scope at the end of the function.

Comments
  • 1
    If I get a lot more invested in the Rust ecosystem I'll make a tool that forces you to call mem::drop on every non-Copy value.
  • 0
    If that's an issue, your functions are too big and should be split.
  • 0
    @aggelalex Some functions can't be split very well because there's a lot of shared data or because there are procedurally enforced invariants which can't be easily visually verified unless all points of interest are colocated.

    Also, this can be said about everything from static typing to memory management. Rust's main innovation is precisely that almost everything is explicit but verified, so your code doesn't have to be pristine in order to be able to assert invariants.
  • 0
    @aggelalex All I'm suggesting is to add "this code doesn't destroy any objects of this type" to the set of possible assertions Rust helps verify.
Add Comment