From 60b799aa324e83ab29908fd3b945f05c33a82598 Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Sun, 21 Aug 2016 17:01:26 -0400 Subject: [PATCH] add links to interesting items in `std::ptr` documentation r? @steveklabnik wrap docs --- src/libcore/intrinsics.rs | 15 ++++++++++----- src/libcore/ptr.rs | 26 ++++++++++++++++---------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index c645608dda790..0a40a5d0b1462 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -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(to_drop: *mut T); diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 925cdfec900db..6b3e72b29a9cb 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -114,11 +114,14 @@ pub unsafe fn replace(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`]). 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 /// /// # Examples /// @@ -206,11 +209,14 @@ pub unsafe fn write(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`]). 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 /// /// # Examples ///