diff options
| author | bors <bors@rust-lang.org> | 2020-11-21 20:18:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-11-21 20:18:11 +0000 |
| commit | da384694807172f0ca40eca2e49a11688aba6e93 (patch) | |
| tree | b1b379214fe7fc680444775c1514583c70d71bea /library/alloc/src | |
| parent | 3adedb8f4c5bb71e9e8a21a047cf8ed121ce0e75 (diff) | |
| parent | 68c9caa6f69d015f39a25e5acbcf90f9a72c7287 (diff) | |
| download | rust-da384694807172f0ca40eca2e49a11688aba6e93.tar.gz rust-da384694807172f0ca40eca2e49a11688aba6e93.zip | |
Auto merge of #79273 - Dylan-DPC:rollup-zd10xlt, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #77844 (clarify rules for ZST Boxes) - #79067 (Refactor the abi handling code a bit) - #79182 (Fix links to extern types in rustdoc (fixes #78777)) - #79231 (Exhaustively match in variant count instrinsic) - #79238 (Direct RUSTC_LOG (tracing/log) output to stderr instead of stdout.) - #79256 (Fix typos) - #79264 (Get rid of some doctree items) - #79272 (Support building clone shims for arrays with generic size) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/boxed.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 1512235da6a..b9490c44f4b 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -62,6 +62,13 @@ //! 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. 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 //! (i.e. the C type `T*`). This means that if you have extern "C" @@ -125,6 +132,7 @@ //! [`Global`]: crate::alloc::Global //! [`Layout`]: crate::alloc::Layout //! [`Layout::for_value(&*value)`]: crate::alloc::Layout::for_value +//! [valid]: ptr#safety #![stable(feature = "rust1", since = "1.0.0")] @@ -530,7 +538,10 @@ impl<T: ?Sized> Box<T> { /// memory problems. For example, a double-free may occur if the /// function is called twice on the same raw pointer. /// + /// The safety conditions are described in the [memory layout] section. + /// /// # Examples + /// /// Recreate a `Box` which was previously converted to a raw pointer /// using [`Box::into_raw`]: /// ``` |
