]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #60963 - blkerby:boxed_docs, r=alexcrichton
authorMazdak Farrokhzad <twingoow@gmail.com>
Wed, 22 May 2019 01:47:32 +0000 (03:47 +0200)
committerGitHub <noreply@github.com>
Wed, 22 May 2019 01:47:32 +0000 (03:47 +0200)
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::<T>::from_raw(value). Conversely, the memory backing a value: *mut T obtained from Box::<T>::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`.


Trivial merge