Skip to content

Commit

Permalink
Rollup merge of rust-lang#35880 - matthew-piziak:ptr-linking, r=steve…
Browse files Browse the repository at this point in the history
…klabnik

add links to interesting items in `std::ptr` documentation

r? @steveklabnik
  • Loading branch information
steveklabnik committed Aug 25, 2016
2 parents 5729fc6 + 33560ee commit 8912567
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 @@ -193,11 +199,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 8912567

Please sign in to comment.