Skip to content

Commit 33560ee

Browse files
add links to interesting items in std::ptr documentation
r? @steveklabnik add links for Box, Rc, and Vec
1 parent 7ac11ca commit 33560ee

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/libcore/intrinsics.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,20 @@ extern "rust-intrinsic" {
224224
/// trait objects, because they can't be read out onto the stack and
225225
/// dropped normally.
226226
///
227-
/// * It is friendlier to the optimizer to do this over `ptr::read` when
228-
/// dropping manually allocated memory (e.g. when writing Box/Rc/Vec),
229-
/// as the compiler doesn't need to prove that it's sound to elide the
230-
/// copy.
227+
/// * It is friendlier to the optimizer to do this over [`ptr::read`] when
228+
/// dropping manually allocated memory (e.g. when writing
229+
/// [`Box`]/[`Rc`]/[`Vec`]), as the compiler doesn't need to prove that
230+
/// it's sound to elide the copy.
231231
///
232232
/// # Undefined Behavior
233233
///
234-
/// This has all the same safety problems as `ptr::read` with respect to
234+
/// This has all the same safety problems as [`ptr::read`] with respect to
235235
/// invalid pointers, types, and double drops.
236+
///
237+
/// [`ptr::read`]: fn.read.html
238+
/// [`Box`]: ../boxed/struct.Box.html
239+
/// [`Rc`]: ../rc/struct.Rc.html
240+
/// [`Vec`]: ../vec/struct.Vec.html
236241
#[stable(feature = "drop_in_place", since = "1.8.0")]
237242
pub fn drop_in_place<T: ?Sized>(to_drop: *mut T);
238243

src/libcore/ptr.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,17 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
114114
/// # Safety
115115
///
116116
/// Beyond accepting a raw pointer, this is unsafe because it semantically
117-
/// moves the value out of `src` without preventing further usage of `src`.
118-
/// If `T` is not `Copy`, then care must be taken to ensure that the value at
119-
/// `src` is not used before the data is overwritten again (e.g. with `write`,
120-
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
121-
/// because it will attempt to drop the value previously at `*src`.
117+
/// moves the value out of `src` without preventing further usage of `src`. If
118+
/// `T` is not [`Copy`], then care must be taken to ensure that the value at
119+
/// `src` is not used before the data is overwritten again (e.g. with
120+
/// [`write`], [`zero_memory`], or [`copy_memory`]). Note that `*src = foo`
121+
/// counts as a use because it will attempt to drop the value previously at
122+
/// `*src`.
123+
///
124+
/// [`Copy`]: ../marker/trait.Copy.html
125+
/// [`write`]: fn.write.html
126+
/// [`zero_memory`]: fn.zero_memory.html
127+
/// [`copy_memory`]: fn.copy_memory.html
122128
///
123129
/// # Examples
124130
///
@@ -206,11 +212,17 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
206212
/// # Safety
207213
///
208214
/// Beyond accepting a raw pointer, this is unsafe because it semantically
209-
/// moves the value out of `src` without preventing further usage of `src`.
210-
/// If `T` is not `Copy`, then care must be taken to ensure that the value at
211-
/// `src` is not used before the data is overwritten again (e.g. with `write`,
212-
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
213-
/// because it will attempt to drop the value previously at `*src`.
215+
/// moves the value out of `src` without preventing further usage of `src`. If
216+
/// `T` is not [`Copy`], then care must be taken to ensure that the value at
217+
/// `src` is not used before the data is overwritten again (e.g. with
218+
/// [`write`], [`zero_memory`], or [`copy_memory`]). Note that `*src = foo`
219+
/// counts as a use because it will attempt to drop the value previously at
220+
/// `*src`.
221+
///
222+
/// [`Copy`]: ../marker/trait.Copy.html
223+
/// [`write`]: fn.write.html
224+
/// [`zero_memory`]: fn.zero_memory.html
225+
/// [`copy_memory`]: fn.copy_memory.html
214226
///
215227
/// # Examples
216228
///

0 commit comments

Comments
 (0)