Skip to content

note that calling drop() explicitly is a compiler error - #35710

Merged
bors merged 1 commit into
rust-lang:masterfrom
matthew-piziak:explicit-drop
Aug 20, 2016
Merged

note that calling drop() explicitly is a compiler error#35710
bors merged 1 commit into
rust-lang:masterfrom
matthew-piziak:explicit-drop

Conversation

@matthew-piziak

Copy link
Copy Markdown
Contributor

Part of #29365

@rust-highfive

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

r? @steveklabnik

Comment threadsrc/libcore/ops.rs Outdated

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

TIL! Thanks!

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
Member

Please squash your commits.

Comment threadsrc/libcore/ops.rs Outdated

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

@bors: r+ rollup

@bors

bors commented Aug 18, 2016

Copy link
Copy Markdown
Collaborator

📌 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
@sophiajtsophiajt mentioned this pull request Aug 19, 2016
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
@sophiajtsophiajt mentioned this pull request Aug 19, 2016
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
@sophiajtsophiajt mentioned this pull request Aug 20, 2016
Sign up for freeto 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

@matthew-piziak@rust-highfive@GuillaumeGomez@steveklabnik@bors@nagisa@apasel422@brson