Skip to content

Commit

Permalink
Document return value of zero-size/zero-heap pointer types.
Browse files Browse the repository at this point in the history
Fixes #39625.
  • Loading branch information
frewsxcv committed Feb 12, 2017
1 parent 29dece1 commit 525f3df
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ impl<T> Arc<T> {
/// To avoid a memory leak the pointer must be converted back to an `Arc` using
/// [`Arc::from_raw`][from_raw].
///
/// If `T` is zero-sized (e.g. `Arc<()>`), the returned pointer address
/// will be meaningless.
///
/// [from_raw]: struct.Arc.html#method.from_raw
///
/// # Examples
Expand Down
3 changes: 3 additions & 0 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ impl<T: ?Sized> Box<T> {
/// proper way to do so is to convert the raw pointer back into a
/// `Box` with the [`Box::from_raw`] function.
///
/// If `T` is zero-sized (e.g. `Box<()>`), the returned pointer address
/// will be meaningless.
///
/// Note: this is an associated function, which means that you have
/// to call it as `Box::into_raw(b)` instead of `b.into_raw()`. This
/// is so that there is no conflict with a method on the inner type.
Expand Down
3 changes: 3 additions & 0 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ impl<T> Rc<T> {
/// To avoid a memory leak the pointer must be converted back to an `Rc` using
/// [`Rc::from_raw`][from_raw].
///
/// If `T` is zero-sized (e.g. `Rc<()>`), the returned pointer address
/// will be meaningless.
///
/// [from_raw]: struct.Rc.html#method.from_raw
///
/// # Examples
Expand Down
6 changes: 6 additions & 0 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ impl<T> [T] {
/// The caller must ensure that the slice outlives the pointer this
/// function returns, or else it will end up pointing to garbage.
///
/// If the slice is empty, the returned pointer address will be
/// meaningless.
///
/// Modifying the slice may cause its buffer to be reallocated, which
/// would also make any pointers to it invalid.
///
Expand All @@ -463,6 +466,9 @@ impl<T> [T] {
/// The caller must ensure that the slice outlives the pointer this
/// function returns, or else it will end up pointing to garbage.
///
/// If the slice is empty, the returned pointer address will be
/// meaningless.
///
/// Modifying the slice may cause its buffer to be reallocated, which
/// would also make any pointers to it invalid.
///
Expand Down
3 changes: 3 additions & 0 deletions src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ impl str {
/// [`u8`]. This pointer will be pointing to the first byte of the string
/// slice.
///
/// If the string slice is empty, the returned pointer address will be
/// meaningless.
///
/// [`u8`]: primitive.u8.html
///
/// # Examples
Expand Down
9 changes: 9 additions & 0 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ impl<T:Copy> Cell<T> {

/// Returns a raw pointer to the underlying data in this cell.
///
/// If `T` is zero-sized (e.g. `Cell<()>`), the returned pointer address
/// will be meaningless.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -771,6 +774,9 @@ impl<T: ?Sized> RefCell<T> {

/// Returns a raw pointer to the underlying data in this cell.
///
/// If `T` is zero-sized (e.g. `RefCell<()>`), the returned pointer address
/// will be meaningless.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -1188,6 +1194,9 @@ impl<T: ?Sized> UnsafeCell<T> {
/// `&mut T`, and ensure that there are no mutations or mutable
/// aliases going on when casting to `&T`
///
/// If `T` is zero-sized (e.g. `UnsafeCell<()>`), the returned pointer
/// address will be meaningless.
///
/// # Examples
///
/// ```
Expand Down

0 comments on commit 525f3df

Please sign in to comment.