Hacker News new | ask | show | jobs
by NieDzejkob 1620 days ago
That is a common misconception. The destructor runs at the end of the scope. Try putting a println in a drop impl.
1 comments

If you do this with C++ destructors, they will sure enough fire at the end of the scope. Even if your String is long gone, the destructor fires anyway, destroying... a hollowed out String left behind to satisfy the destructor.

But go ahead and try it in Rust, your print doesn't happen because nothing was actually dropped. The String was moved, and so there isn't anything to drop.

https://gist.github.com/rust-play/4bbcc2a4efb641e578e84a1962...