Uh oh!
There was an error while loading. Please reload this page.
Don't recommend ManuallyDrop to customize drop order - #76150
Conversation
rust-highfive
commented
Aug 31, 2020
(rust_highfive has picked a reviewer for you, use r? to override) |
crlf0710
commented
Sep 18, 2020
r? @dtolnay |
withoutboats
commented
Sep 18, 2020
I agree with this change to the guideline. I don't know if these docs date to before we had agreed to define the drop order or not. I would like the documentation to briefly explain the defined drop order of struct fields, though, and maybe the code sample using that to get a certain drop order. I know its contained in the associated link, but it would make the documentation clearer here. |
See https://internals.rust-lang.org/t/need-for-controlling-drop-order-of-fields/12914/21 for the discussion. TL;DR: ManuallyDrop is unsafe and footguny, but you can just ask the compiler to do all the work for you by re-ordering declarations.
matklad
commented
Sep 21, 2020
Yeah, that would be helpful, included an example! |
RalfJung
commented
Sep 21, 2020
r=me unless you want another review. |
withoutboats
commented
Sep 21, 2020
@bors r+ looks good! |
bors
commented
Sep 21, 2020
📌 Commit 60b102d has been approved by |
ecstatic-morse
commented
Sep 21, 2020
@bors rollup |
Don't recommend ManuallyDrop to customize drop order See https://internals.rust-lang.org/t/need-for-controlling-drop-order-of-fields/12914/21 for the discussion. TL;DR: ManuallyDrop is unsafe and footguny, but you can just ask the compiler to do all the work for you by re-ordering declarations. Specifically, the original example from the docs is much better written as ```rust struct Peach; struct Banana; struct Melon; struct FruitBox { melon: Melon, // XXX: mind the relative drop order of the fields below peach: Peach, banana: Banana, } ```
Don't recommend ManuallyDrop to customize drop order See https://internals.rust-lang.org/t/need-for-controlling-drop-order-of-fields/12914/21 for the discussion. TL;DR: ManuallyDrop is unsafe and footguny, but you can just ask the compiler to do all the work for you by re-ordering declarations. Specifically, the original example from the docs is much better written as ```rust struct Peach; struct Banana; struct Melon; struct FruitBox { melon: Melon, // XXX: mind the relative drop order of the fields below peach: Peach, banana: Banana, } ```
…atic-morse Rollup of 13 pull requests Successful merges: - rust-lang#72734 (Reduce duplicate in liballoc reserve error handling) - rust-lang#76131 (Don't use `zip` to compare iterators during pretty-print hack) - rust-lang#76150 (Don't recommend ManuallyDrop to customize drop order) - rust-lang#76275 (Implementation of Write for some immutable ref structs) - rust-lang#76489 (Add explanation for E0756) - rust-lang#76581 (do not ICE on bound variables, return `TooGeneric` instead) - rust-lang#76655 (Make some methods of `Pin` unstable const) - rust-lang#76783 (Only get ImplKind::Impl once) - rust-lang#76807 (Use const-checking to forbid use of unstable features in const-stable functions) - rust-lang#76888 (use if let instead of single match arm expressions) - rust-lang#76914 (extend `Ty` and `TyCtxt` lints to self types) - rust-lang#77022 (Reduce boilerplate for BytePos and CharPos) - rust-lang#77032 (lint missing docs for extern items) Failed merges: r? `@ghost`
vojtechkral
commented
Sep 25, 2020
Reminder: Rustonomicon (still?) advises exactly the other way around 🙂 |
See
https://internals.rust-lang.org/t/need-for-controlling-drop-order-of-fields/12914/21
for the discussion.
TL;DR: ManuallyDrop is unsafe and footguny, but you can just ask the compiler to do all the work for you by re-ordering declarations.
Specifically, the original example from the docs is much better written as