Skip to content

Commit a037128

Browse files
committed
fix: add aliasing rules for Box
1 parent 9f32ccf commit a037128

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

library/alloc/src/boxed.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,11 @@ impl<T: ?Sized> Box<T> {
998998
/// memory problems. For example, a double-free may occur if the
999999
/// function is called twice on the same raw pointer.
10001000
///
1001+
/// The ownership of `raw` is effectively transferred to the resulting
1002+
/// `Box<T>` which may then deallocate or change the contents of memory
1003+
/// pointed to by the pointer at will. You must ensure that nothing else uses
1004+
/// the pointer after calling this function.
1005+
///
10011006
/// The raw pointer must point to a block of memory allocated by the global allocator.
10021007
///
10031008
/// The safety conditions are described in the [memory layout] section.
@@ -1047,6 +1052,11 @@ impl<T: ?Sized> Box<T> {
10471052
/// memory problems. For example, a double-free may occur if the
10481053
/// function is called twice on the same `NonNull` pointer.
10491054
///
1055+
/// The ownership of `ptr` is effectively transferred to the resulting
1056+
/// `Box<T>` which may then deallocate or change the contents of memory
1057+
/// pointed to by the pointer at will. You must ensure that nothing else uses
1058+
/// the pointer after calling this function.
1059+
///
10501060
/// The non-null pointer must point to a block of memory allocated by the global allocator.
10511061
///
10521062
/// The safety conditions are described in the [memory layout] section.
@@ -1221,6 +1231,11 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12211231
/// memory problems. For example, a double-free may occur if the
12221232
/// function is called twice on the same raw pointer.
12231233
///
1234+
/// The ownership of `raw` is effectively transferred to the resulting
1235+
/// `Box<T>` which may then deallocate or change the contents of memory
1236+
/// pointed to by the pointer at will. You must ensure that nothing else uses
1237+
/// the pointer after calling this function.
1238+
///
12241239
/// The raw pointer must point to a block of memory allocated by `alloc`.
12251240
///
12261241
/// # Examples
@@ -1274,6 +1289,11 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12741289
/// memory problems. For example, a double-free may occur if the
12751290
/// function is called twice on the same raw pointer.
12761291
///
1292+
/// The ownership of `raw` is effectively transferred to the resulting
1293+
/// `Box<T>` which may then deallocate or change the contents of memory
1294+
/// pointed to by the pointer at will. You must ensure that nothing else uses
1295+
/// the pointer after calling this function.
1296+
///
12771297
/// The non-null pointer must point to a block of memory allocated by `alloc`.
12781298
///
12791299
/// # Examples

0 commit comments

Comments
 (0)