about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorLemonJ <1632798336@qq.com>2025-01-21 16:25:56 +0800
committerLemonJ <1632798336@qq.com>2025-01-21 16:25:56 +0800
commit2fd629654fb08884a5f00f1589c3dd172eee2b5a (patch)
tree9b8783156439e6834bd5a773999c980bc9c4d936 /library/alloc/src
parentb605c65b6eb5fa71783f8e26df69975f9f1680ee (diff)
downloadrust-2fd629654fb08884a5f00f1589c3dd172eee2b5a.tar.gz
rust-2fd629654fb08884a5f00f1589c3dd172eee2b5a.zip
add missing allocator safety in alloc crate
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