about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-01-02 06:56:57 +0000
committerbors <bors@rust-lang.org>2025-01-02 06:56:57 +0000
commitbf6f8a4d328f7f3b0f6ea8205ad28591cc11aafd (patch)
treed010255f0797fce139ec996a65a362e9e7a26d58
parentc528b8c67895bfe7fdcdfeb56ec5bf6ef928dcd7 (diff)
parenta5494a8e6cc9796b7e0ccd0838ae74509203c8a2 (diff)
downloadrust-bf6f8a4d328f7f3b0f6ea8205ad28591cc11aafd.tar.gz
rust-bf6f8a4d328f7f3b0f6ea8205ad28591cc11aafd.zip
Auto merge of #135009 - DiuDiu777:box-doc, r=jhpratt
Fix doc for missing Box allocator consistency

### Description:
This PR addresses missing document regarding consistency of `Box::from_raw` and `Box::from_raw_in`.

- [from_raw](https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html#method.from_raw): The document now misses the raw pointer passed to `Box::from_raw` must point to a block of memory allocated by the `Global Allocator` (specified in source code).

- [from_raw_in](https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html#method.from_raw_in): The safety conditions don't include the allocator consistency.

Besides, [Boxed Memory Layout](https://doc.rust-lang.org/nightly/std/boxed/index.html#memory-layout) doesn't explicitly cover the allocator consistency issue.

This change builds upon the improvements made in [PR #134496](https://github.com/rust-lang/rust/pull/134496).
-rw-r--r--library/alloc/src/boxed.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs
index ca3bd24a420..05e5d712a27 100644
--- a/library/alloc/src/boxed.rs
+++ b/library/alloc/src/boxed.rs
@@ -1045,6 +1045,8 @@ 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 raw pointer must point to a block of memory allocated by the global allocator.
+    ///
     /// The safety conditions are described in the [memory layout] section.
     ///
     /// # Examples
@@ -1148,6 +1150,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
     /// memory problems. For example, a double-free may occur if the
     /// function is called twice on the same raw pointer.
     ///
+    /// The raw pointer must point to a block of memory allocated by `alloc`
     ///
     /// # Examples
     ///