-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
note that calling drop() explicitly is a compiler error #35710
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@@ -102,6 +102,9 @@ pub trait Drop { | |||
/// | |||
/// After this function is over, the memory of `self` will be deallocated. | |||
/// | |||
/// This function cannot be called explicitly. This is compiler error | |||
/// [0040](https://doc.rust-lang.org/error-index.html#E0040). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should mention that there’s a drop<T>(t: T)
function in prelude which will call it for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a mention. Out of curiosity, do you know why calling the destructor is discouraged when it's easy enough to call std::mem::drop
(which would be easy enough to write even if it didn't exist)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the destructor does not take ownership. There’s a ton of book-keeping minutiæ going behind the covers other than just calling the destructor when a type is dropped too. Simply calling the Drop::drop
wouldn’t really drop the type, only run the destructor.
Please squash your commits. |
136cfb3
to
da2bfff
Compare
@@ -102,6 +102,13 @@ pub trait Drop { | |||
/// | |||
/// After this function is over, the memory of `self` will be deallocated. | |||
/// | |||
/// This function cannot be called explicitly. This is compiler error | |||
/// [0040] However, the [std::mem::drop<T>(t:T)] function in the prelude |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should just be std::mem::drop
, and with the graves
da2bfff
to
26a11d8
Compare
Part of rust-lang#29365 explain that std::mem::drop in prelude will invoke Drop change "prelude" -> "the prelude"; change links to reference-style move link references to links' section
0d659c1
to
a516dbb
Compare
@bors: r+ rollup |
📌 Commit a516dbb has been approved by |
…veklabnik note that calling drop() explicitly is a compiler error Part of rust-lang#29365
…veklabnik note that calling drop() explicitly is a compiler error Part of rust-lang#29365
…veklabnik note that calling drop() explicitly is a compiler error Part of rust-lang#29365
…veklabnik note that calling drop() explicitly is a compiler error Part of rust-lang#29365
…veklabnik note that calling drop() explicitly is a compiler error Part of rust-lang#29365
Part of #29365