Skip to content

Document destructors/drop. - #128

Merged
Havvy merged 1 commit into
rust-lang:masterfrom
matthewjasper:destruction
Oct 30, 2017
Merged

Havvy merged 1 commit into
rust-lang:masterfrom
matthewjasper:destruction

Conversation

@matthewjasper

Copy link
Copy Markdown
Contributor

@Havvy Havvy left a comment

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.

Little things, but mostly good.

Comment thread 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
Copy Markdown
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.

Comment thread src/destructors.md Outdated
@@ -0,0 +1,95 @@
# Destructors

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

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.

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

Comment thread src/destructors.md Outdated
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
Copy Markdown
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.

Comment thread src/destructors.md Outdated

## Not running destructors

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

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.

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

Comment thread src/destructors.md Outdated
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
Copy Markdown
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.

Comment thread src/destructors.md

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

Variables are dropped in reverse order of declaration. Variables declared in

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.

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

@Havvy

Havvy commented Oct 30, 2017 •

Copy link
Copy Markdown
Contributor

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

Havvy commented Oct 30, 2017

Copy link
Copy Markdown
Contributor

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

@matthewjasper
matthewjasper deleted the destruction branch October 18, 2018 21:00
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.

2 participants