Repository navigation
Document destructors/drop. - #128
Conversation
2a360d7 to
bbbc743
Compare
Havvy
left a comment
There was a problem hiding this comment.
Little things, but mostly good.
| ### 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.
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 | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Nit: The parenthesis around "owned" aren't needed.
|
|
||
| ## Not running destructors | ||
|
|
||
| Not running destructors in Rust is safe, so `unsafe` code cannot assume a |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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