about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorJethro Beekman <jethro@fortanix.com>2019-02-05 16:56:19 +0530
committerJethro Beekman <jethro@fortanix.com>2019-02-13 12:51:59 +0530
commite41e694d9e5a6bcb2109c936df9757879a65eb59 (patch)
tree927e2abc8244a62aa57e0584fd33f4fbf50dfbb0 /src/liballoc
parent8ae730a442cc8af6a487a137ae9ba78f89edbba6 (diff)
downloadrust-e41e694d9e5a6bcb2109c936df9757879a65eb59.tar.gz
rust-e41e694d9e5a6bcb2109c936df9757879a65eb59.zip
Clarify guarantees for `Box` allocation
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/alloc.rs3
-rw-r--r--src/liballoc/boxed.rs10
2 files changed, 13 insertions, 0 deletions
diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs
index ec652df3b37..f3877e51a66 100644
--- a/src/liballoc/alloc.rs
+++ b/src/liballoc/alloc.rs
@@ -34,6 +34,9 @@ extern "Rust" {
 /// This type implements the [`Alloc`] trait by forwarding calls
 /// to the allocator registered with the `#[global_allocator]` attribute
 /// if there is one, or the `std` crate’s default.
+///
+/// Note: while this type is unstable, the functionality it provides can be
+/// accessed through the [free functions in `alloc`](index.html#functions).
 #[unstable(feature = "allocator_api", issue = "32838")]
 #[derive(Copy, Clone, Default, Debug)]
 pub struct Global;
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index 8e01e12e0b8..462f65ed794 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -4,6 +4,16 @@
 //! heap allocation in Rust. Boxes provide ownership for this allocation, and
 //! drop their contents when they go out of scope.
 //!
+//! For non-zero-sized values, a [`Box`] will use the [`Global`] allocator for
+//! its allocation. 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)`.
+//!
 //! # Examples
 //!
 //! Move a value from the stack to the heap by creating a [`Box`]: