Skip to content

Commit

Permalink
add links to interesting items in std::ptr documentation
Browse files Browse the repository at this point in the history
r? @steveklabnik

add links for Box, Rc, and Vec
  • Loading branch information
matthew-piziak committed Aug 22, 2016
1 parent 7ac11ca commit 33560ee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
15 changes: 10 additions & 5 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,20 @@ extern "rust-intrinsic" {
/// trait objects, because they can't be read out onto the stack and
/// dropped normally.
///
/// * It is friendlier to the optimizer to do this over `ptr::read` when
/// dropping manually allocated memory (e.g. when writing Box/Rc/Vec),
/// as the compiler doesn't need to prove that it's sound to elide the
/// copy.
/// * It is friendlier to the optimizer to do this over [`ptr::read`] when
/// dropping manually allocated memory (e.g. when writing
/// [`Box`]/[`Rc`]/[`Vec`]), as the compiler doesn't need to prove that
/// it's sound to elide the copy.
///
/// # Undefined Behavior
///
/// This has all the same safety problems as `ptr::read` with respect to
/// This has all the same safety problems as [`ptr::read`] with respect to
/// invalid pointers, types, and double drops.
///
/// [`ptr::read`]: fn.read.html
/// [`Box`]: ../boxed/struct.Box.html
/// [`Rc`]: ../rc/struct.Rc.html
/// [`Vec`]: ../vec/struct.Vec.html
#[stable(feature = "drop_in_place", since = "1.8.0")]
pub fn drop_in_place<T: ?Sized>(to_drop: *mut T);

Expand Down
32 changes: 22 additions & 10 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,17 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
/// # Safety
///
/// Beyond accepting a raw pointer, this is unsafe because it semantically
/// moves the value out of `src` without preventing further usage of `src`.
/// If `T` is not `Copy`, then care must be taken to ensure that the value at
/// `src` is not used before the data is overwritten again (e.g. with `write`,
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
/// because it will attempt to drop the value previously at `*src`.
/// moves the value out of `src` without preventing further usage of `src`. If
/// `T` is not [`Copy`], then care must be taken to ensure that the value at
/// `src` is not used before the data is overwritten again (e.g. with
/// [`write`], [`zero_memory`], or [`copy_memory`]). Note that `*src = foo`
/// counts as a use because it will attempt to drop the value previously at
/// `*src`.
///
/// [`Copy`]: ../marker/trait.Copy.html
/// [`write`]: fn.write.html
/// [`zero_memory`]: fn.zero_memory.html
/// [`copy_memory`]: fn.copy_memory.html
///
/// # Examples
///
Expand Down Expand Up @@ -206,11 +212,17 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
/// # Safety
///
/// Beyond accepting a raw pointer, this is unsafe because it semantically
/// moves the value out of `src` without preventing further usage of `src`.
/// If `T` is not `Copy`, then care must be taken to ensure that the value at
/// `src` is not used before the data is overwritten again (e.g. with `write`,
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
/// because it will attempt to drop the value previously at `*src`.
/// moves the value out of `src` without preventing further usage of `src`. If
/// `T` is not [`Copy`], then care must be taken to ensure that the value at
/// `src` is not used before the data is overwritten again (e.g. with
/// [`write`], [`zero_memory`], or [`copy_memory`]). Note that `*src = foo`
/// counts as a use because it will attempt to drop the value previously at
/// `*src`.
///
/// [`Copy`]: ../marker/trait.Copy.html
/// [`write`]: fn.write.html
/// [`zero_memory`]: fn.zero_memory.html
/// [`copy_memory`]: fn.copy_memory.html
///
/// # Examples
///
Expand Down

0 comments on commit 33560ee

Please sign in to comment.