about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-01-28 14:23:23 +0100
committerGitHub <noreply@github.com>2025-01-28 14:23:23 +0100
commit32c04fc509b6adadcab018197e78e375cd778560 (patch)
tree54cb0540f79a818650f2b7a3aa1c2ab4a930c4e0 /library/alloc/src
parent21ddd7ab89355b93c6555f5500059ae76b858321 (diff)
parent2fd629654fb08884a5f00f1589c3dd172eee2b5a (diff)
downloadrust-32c04fc509b6adadcab018197e78e375cd778560.tar.gz
rust-32c04fc509b6adadcab018197e78e375cd778560.zip
Rollup merge of #135805 - DiuDiu777:master, r=Noratrieb
Add missing allocator safety in alloc crate

### PR Description
In the previous PR [#135009](https://github.com/rust-lang/rust/pull/135009), PR [#134496](https://github.com/rust-lang/rust/pull/134496), some incomplete API documentation issues have been fixed.

Based on these changes,  other inconsistencies related to the allocator have also been identified, including:

- `Box::from_non_null`
- `Box::from_non_null_in`
- `Weak::from_raw`
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/boxed.rs5
-rw-r--r--library/alloc/src/sync.rs2
2 files changed, 5 insertions, 2 deletions
diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs
index 1b5e44a9134..8b38e6fc259 100644
--- a/library/alloc/src/boxed.rs
+++ b/library/alloc/src/boxed.rs
@@ -1115,6 +1115,8 @@ impl<T: ?Sized> Box<T> {
     /// memory problems. For example, a double-free may occur if the
     /// function is called twice on the same `NonNull` pointer.
     ///
+    /// The non-null pointer must point to a block of memory allocated by the global allocator.
+    ///
     /// The safety conditions are described in the [memory layout] section.
     ///
     /// # Examples
@@ -1170,7 +1172,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`
+    /// The raw pointer must point to a block of memory allocated by `alloc`.
     ///
     /// # Examples
     ///
@@ -1225,6 +1227,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 non-null pointer must point to a block of memory allocated by `alloc`.
     ///
     /// # Examples
     ///
diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs
index 8eee7cff208..431e19e6ef1 100644
--- a/library/alloc/src/sync.rs
+++ b/library/alloc/src/sync.rs
@@ -2740,7 +2740,7 @@ impl<T: ?Sized> Weak<T> {
     /// # Safety
     ///
     /// The pointer must have originated from the [`into_raw`] and must still own its potential
-    /// weak reference.
+    /// weak reference, and must point to a block of memory allocated by global allocator.
     ///
     /// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this
     /// takes ownership of one weak reference currently represented as a raw pointer (the weak