Skip to content

Document destructors/drop. #128

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Oct 30, 2017
Merged

Conversation

matthewjasper
Copy link
Contributor

Copy link
Contributor

@Havvy Havvy left a comment

Choose a reason for hiding this comment

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

Little things, but mostly good.

src/glossory.md Outdated
### Initialized

A variable is initialized if it has been assigned a value and hasn't since been
moved from. All other lvalues are assumed to be initialized (only unsafe Rust
Copy link
Contributor

Choose a reason for hiding this comment

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

The parenthetical should just be its own sentence.

@@ -0,0 +1,95 @@
# Destructors

When an [intialized] [variable] in Rust goes out of scope or a [temporary] is
Copy link
Contributor

Choose a reason for hiding this comment

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

Need a \ before the opening bracket on [variable].

2. Recursively running the destructor of all of its fields.
* The fields of a [struct], [tuple] or [enum variant] are dropped in
declaration order. \*
* The elements of an [array] or (owned) [slice][array] are dropped from the
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: The parenthesis around "owned" aren't needed.


## Not running destructors

Not running destructors in Rust is safe, so `unsafe` code cannot assume a
Copy link
Contributor

Choose a reason for hiding this comment

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

The entire unsafe middle clause feels unneeded. There's a section devoted to behaviour considered safe that includes leaking memory (though it can be better documented there).

Not running destructors in Rust is safe, so `unsafe` code cannot assume a
variable will be dropped, even if it has a type that isn't `'static`.
[`std::mem::forget`] can be used to avoid running the destructor of a local
variable. [`std::mem::ManuallyDrop`] provides a wrapper to prevent a field
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather this just say that ManuallyDrop provides a convenient wrapper to prevent a variable or field from being dropped automatically. While it's used for avoiding recursive drops, it's used for other reasons as well. E.g. forget actually just puts the value into a ManuallyDrop and then lets Rust drop it without calling the drop method.


\* This order was stabilized in [RFC 1857].

Variables are dropped in reverse order of declaration. Variables declared in
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be a part of block expressions, but I'm not going to worry about that for this PR.

@Havvy
Copy link
Contributor

Havvy commented Oct 30, 2017

Apparently I don't get a notification when there are new commits. I'll look at this when I get home right now.

@Havvy Havvy merged commit 1928fdd into rust-lang:master Oct 30, 2017
@Havvy
Copy link
Contributor

Havvy commented Oct 30, 2017

💟 Thanks! And 🙁 sorry for not noticing the second commit sooner.

@matthewjasper matthewjasper deleted the destruction branch October 18, 2018 21:00
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants