Skip to content

Commit 525f3df

Browse files
committed
Document return value of zero-size/zero-heap pointer types.
Fixes #39625.
1 parent 29dece1 commit 525f3df

File tree

6 files changed

+27
-0
lines changed

6 files changed

+27
-0
lines changed

src/liballoc/arc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ impl<T> Arc<T> {
282282
/// To avoid a memory leak the pointer must be converted back to an `Arc` using
283283
/// [`Arc::from_raw`][from_raw].
284284
///
285+
/// If `T` is zero-sized (e.g. `Arc<()>`), the returned pointer address
286+
/// will be meaningless.
287+
///
285288
/// [from_raw]: struct.Arc.html#method.from_raw
286289
///
287290
/// # Examples

src/liballoc/boxed.rs

+3
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ impl<T: ?Sized> Box<T> {
274274
/// proper way to do so is to convert the raw pointer back into a
275275
/// `Box` with the [`Box::from_raw`] function.
276276
///
277+
/// If `T` is zero-sized (e.g. `Box<()>`), the returned pointer address
278+
/// will be meaningless.
279+
///
277280
/// Note: this is an associated function, which means that you have
278281
/// to call it as `Box::into_raw(b)` instead of `b.into_raw()`. This
279282
/// is so that there is no conflict with a method on the inner type.

src/liballoc/rc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ impl<T> Rc<T> {
359359
/// To avoid a memory leak the pointer must be converted back to an `Rc` using
360360
/// [`Rc::from_raw`][from_raw].
361361
///
362+
/// If `T` is zero-sized (e.g. `Rc<()>`), the returned pointer address
363+
/// will be meaningless.
364+
///
362365
/// [from_raw]: struct.Rc.html#method.from_raw
363366
///
364367
/// # Examples

src/libcollections/slice.rs

+6
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@ impl<T> [T] {
437437
/// The caller must ensure that the slice outlives the pointer this
438438
/// function returns, or else it will end up pointing to garbage.
439439
///
440+
/// If the slice is empty, the returned pointer address will be
441+
/// meaningless.
442+
///
440443
/// Modifying the slice may cause its buffer to be reallocated, which
441444
/// would also make any pointers to it invalid.
442445
///
@@ -463,6 +466,9 @@ impl<T> [T] {
463466
/// The caller must ensure that the slice outlives the pointer this
464467
/// function returns, or else it will end up pointing to garbage.
465468
///
469+
/// If the slice is empty, the returned pointer address will be
470+
/// meaningless.
471+
///
466472
/// Modifying the slice may cause its buffer to be reallocated, which
467473
/// would also make any pointers to it invalid.
468474
///

src/libcollections/str.rs

+3
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ impl str {
275275
/// [`u8`]. This pointer will be pointing to the first byte of the string
276276
/// slice.
277277
///
278+
/// If the string slice is empty, the returned pointer address will be
279+
/// meaningless.
280+
///
278281
/// [`u8`]: primitive.u8.html
279282
///
280283
/// # Examples

src/libcore/cell.rs

+9
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ impl<T:Copy> Cell<T> {
235235

236236
/// Returns a raw pointer to the underlying data in this cell.
237237
///
238+
/// If `T` is zero-sized (e.g. `Cell<()>`), the returned pointer address
239+
/// will be meaningless.
240+
///
238241
/// # Examples
239242
///
240243
/// ```
@@ -771,6 +774,9 @@ impl<T: ?Sized> RefCell<T> {
771774

772775
/// Returns a raw pointer to the underlying data in this cell.
773776
///
777+
/// If `T` is zero-sized (e.g. `RefCell<()>`), the returned pointer address
778+
/// will be meaningless.
779+
///
774780
/// # Examples
775781
///
776782
/// ```
@@ -1188,6 +1194,9 @@ impl<T: ?Sized> UnsafeCell<T> {
11881194
/// `&mut T`, and ensure that there are no mutations or mutable
11891195
/// aliases going on when casting to `&T`
11901196
///
1197+
/// If `T` is zero-sized (e.g. `UnsafeCell<()>`), the returned pointer
1198+
/// address will be meaningless.
1199+
///
11911200
/// # Examples
11921201
///
11931202
/// ```

0 commit comments

Comments
 (0)