Skip to content
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

Merged
merged 1 commit into from
Aug 20, 2016

Conversation

matthew-piziak
Copy link
Contributor

Part of #29365

@rust-highfive
Copy link
Collaborator

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.

@matthew-piziak
Copy link
Contributor Author

r? @steveklabnik

@rust-highfive rust-highfive assigned steveklabnik and unassigned brson Aug 16, 2016
@@ -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).
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL! Thanks!

Copy link
Contributor Author

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)?

Copy link
Member

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.

@GuillaumeGomez
Copy link
Member

Please squash your commits.

@@ -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
Copy link
Member

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

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
@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Aug 18, 2016

📌 Commit a516dbb has been approved by steveklabnik

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Aug 18, 2016
…veklabnik

note that calling drop() explicitly is a compiler error

Part of rust-lang#29365
sophiajt pushed a commit to sophiajt/rust that referenced this pull request Aug 19, 2016
…veklabnik

note that calling drop() explicitly is a compiler error

Part of rust-lang#29365
sophiajt pushed a commit to sophiajt/rust that referenced this pull request Aug 19, 2016
…veklabnik

note that calling drop() explicitly is a compiler error

Part of rust-lang#29365
sophiajt pushed a commit to sophiajt/rust that referenced this pull request Aug 20, 2016
…veklabnik

note that calling drop() explicitly is a compiler error

Part of rust-lang#29365
sophiajt pushed a commit to sophiajt/rust that referenced this pull request Aug 20, 2016
…veklabnik

note that calling drop() explicitly is a compiler error

Part of rust-lang#29365
bors added a commit that referenced this pull request Aug 20, 2016
@bors bors merged commit a516dbb into rust-lang:master Aug 20, 2016
@matthew-piziak matthew-piziak deleted the explicit-drop branch August 23, 2016 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants