about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-11-20 10:25:59 +0100
committerRalf Jung <post@ralfj.de>2020-11-20 11:09:49 +0100
commita7677f77146bd69b26b5fb5eaa8f88ac080ff347 (patch)
tree1d78c92aa3ca18da943dfc060082572c2099c341 /library/alloc/src
parent0f572a9810e2c54b7067641583a5527acff6cae5 (diff)
downloadrust-a7677f77146bd69b26b5fb5eaa8f88ac080ff347.tar.gz
rust-a7677f77146bd69b26b5fb5eaa8f88ac080ff347.zip
reference NonNull::dangling
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/boxed.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs
index 7fd91aba321..9676572e45d 100644
--- a/library/alloc/src/boxed.rs
+++ b/library/alloc/src/boxed.rs
@@ -62,10 +62,12 @@
 //! T` obtained from [`Box::<T>::into_raw`] may be deallocated using the
 //! [`Global`] allocator with [`Layout::for_value(&*value)`].
 //!
-//! For zero-sized values, the `Box` pointer still has to be [valid] for reads and writes and
-//! sufficiently aligned. In particular, casting any aligned non-zero integer literal to a raw
-//! pointer produces a valid pointer, but a pointer pointing into previously allocated memory that
-//! since got freed is not valid.
+//! For zero-sized values, the `Box` pointer still has to be [valid] for reads
+//! and writes and sufficiently aligned. In particular, casting any aligned
+//! non-zero integer literal to a raw pointer produces a valid pointer, but a
+//! pointer pointing into previously allocated memory that since got freed is
+//! not valid. The recommended way to build a Box to a ZST if `Box::new` cannot
+//! be used is to use [`ptr::NonNull::dangling`].
 //!
 //! So long as `T: Sized`, a `Box<T>` is guaranteed to be represented
 //! as a single pointer and is also ABI-compatible with C pointers