Skip to content

Commit cf42e05

Browse files
matthiaskrgrgitbot
authored and
gitbot
committed
Rollup merge of rust-lang#135805 - DiuDiu777:master, r=Noratrieb
Add missing allocator safety in alloc crate ### PR Description In the previous PR [rust-lang#135009](rust-lang#135009), PR [rust-lang#134496](rust-lang#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`
2 parents c2d176b + 45de455 commit cf42e05

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

alloc/src/boxed.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,8 @@ impl<T: ?Sized> Box<T> {
11151115
/// memory problems. For example, a double-free may occur if the
11161116
/// function is called twice on the same `NonNull` pointer.
11171117
///
1118+
/// The non-null pointer must point to a block of memory allocated by the global allocator.
1119+
///
11181120
/// The safety conditions are described in the [memory layout] section.
11191121
///
11201122
/// # Examples
@@ -1170,7 +1172,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11701172
/// memory problems. For example, a double-free may occur if the
11711173
/// function is called twice on the same raw pointer.
11721174
///
1173-
/// The raw pointer must point to a block of memory allocated by `alloc`
1175+
/// The raw pointer must point to a block of memory allocated by `alloc`.
11741176
///
11751177
/// # Examples
11761178
///
@@ -1225,6 +1227,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12251227
/// memory problems. For example, a double-free may occur if the
12261228
/// function is called twice on the same raw pointer.
12271229
///
1230+
/// The non-null pointer must point to a block of memory allocated by `alloc`.
12281231
///
12291232
/// # Examples
12301233
///

alloc/src/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2740,7 +2740,7 @@ impl<T: ?Sized> Weak<T> {
27402740
/// # Safety
27412741
///
27422742
/// The pointer must have originated from the [`into_raw`] and must still own its potential
2743-
/// weak reference.
2743+
/// weak reference, and must point to a block of memory allocated by global allocator.
27442744
///
27452745
/// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this
27462746
/// takes ownership of one weak reference currently represented as a raw pointer (the weak

0 commit comments

Comments
 (0)