From: Mazdak Farrokhzad Date: Wed, 22 May 2019 01:47:32 +0000 (+0200) Subject: Rollup merge of #60963 - blkerby:boxed_docs, r=alexcrichton X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=40a18a1df52ad3b499b002e4493590f553aae954;p=rust.git Rollup merge of #60963 - blkerby:boxed_docs, r=alexcrichton Update boxed::Box docs on memory layout The existing docs for the `Box` type state that "the way `Box` allocates and releases memory is unspecified", and that therefore the only valid pointer to pass to `Box::from_raw` is one obtained from `Box::into_raw`. This is inconsistent with the module-level docs which specify, > It is valid to convert both ways between a Box and a raw pointer allocated with the Global allocator, given that the Layout used with the allocator is correct for the type. More precisely, a value: *mut T that has been allocated with the Global allocator with Layout::for_value(&*value) may be converted into a box using Box::::from_raw(value). Conversely, the memory backing a value: *mut T obtained from Box::::into_raw may be deallocated using the Global allocator with Layout::for_value(&*value). This pull request updates the docs for `Box` to make them consistent with the module-level docs and adds some examples of how to use the global allocator in conjunction with `Box::from_raw` and `Box::into_raw`. --- 40a18a1df52ad3b499b002e4493590f553aae954