-
Notifications
You must be signed in to change notification settings - Fork 533
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
Conversation
2a360d7
to
bbbc743
Compare
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.
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 |
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.
The parenthetical should just be its own sentence.
src/destructors.md
Outdated
@@ -0,0 +1,95 @@ | |||
# Destructors | |||
|
|||
When an [intialized] [variable] in Rust goes out of scope or a [temporary] is |
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.
Need a \
before the opening bracket on [variable]
.
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 |
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.
Nit: The parenthesis around "owned" aren't needed.
src/destructors.md
Outdated
|
||
## Not running destructors | ||
|
||
Not running destructors in Rust is safe, so `unsafe` code cannot assume a |
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.
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).
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 |
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.
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 |
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.
I think this should be a part of block expressions
, but I'm not going to worry about that for this PR.
bbbc743
to
c9d2f07
Compare
Apparently I don't get a notification when there are new commits. I'll look at this |
💟 Thanks! And 🙁 sorry for not noticing the second commit sooner. |
cc rust-lang/rust#43034