Skip to content

Commit 3fd6295

Browse files
authored
Rollup merge of rust-lang#35880 - matthew-piziak:ptr-linking, r=steveklabnik
add links to interesting items in `std::ptr` documentation r? @steveklabnik
2 parents 0bd1eae + 33560ee commit 3fd6295

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
@@ -222,15 +222,20 @@ extern "rust-intrinsic" {
222222
/// trait objects, because they can't be read out onto the stack and
223223
/// dropped normally.
224224
///
225-
/// * It is friendlier to the optimizer to do this over `ptr::read` when
226-
/// dropping manually allocated memory (e.g. when writing Box/Rc/Vec),
227-
/// as the compiler doesn't need to prove that it's sound to elide the
228-
/// copy.
225+
/// * It is friendlier to the optimizer to do this over [`ptr::read`] when
226+
/// dropping manually allocated memory (e.g. when writing
227+
/// [`Box`]/[`Rc`]/[`Vec`]), as the compiler doesn't need to prove that
228+
/// it's sound to elide the copy.
229229
///
230230
/// # Undefined Behavior
231231
///
232-
/// This has all the same safety problems as `ptr::read` with respect to
232+
/// This has all the same safety problems as [`ptr::read`] with respect to
233233
/// invalid pointers, types, and double drops.
234+
///
235+
/// [`ptr::read`]: fn.read.html
236+
/// [`Box`]: ../boxed/struct.Box.html
237+
/// [`Rc`]: ../rc/struct.Rc.html
238+
/// [`Vec`]: ../vec/struct.Vec.html
234239
#[stable(feature = "drop_in_place", since = "1.8.0")]
235240
pub fn drop_in_place<T: ?Sized>(to_drop: *mut T);
236241

src/libcore/ptr.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,17 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
111111
/// # Safety
112112
///
113113
/// Beyond accepting a raw pointer, this is unsafe because it semantically
114-
/// moves the value out of `src` without preventing further usage of `src`.
115-
/// If `T` is not `Copy`, then care must be taken to ensure that the value at
116-
/// `src` is not used before the data is overwritten again (e.g. with `write`,
117-
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
118-
/// because it will attempt to drop the value previously at `*src`.
114+
/// moves the value out of `src` without preventing further usage of `src`. If
115+
/// `T` is not [`Copy`], then care must be taken to ensure that the value at
116+
/// `src` is not used before the data is overwritten again (e.g. with
117+
/// [`write`], [`zero_memory`], or [`copy_memory`]). Note that `*src = foo`
118+
/// counts as a use because it will attempt to drop the value previously at
119+
/// `*src`.
120+
///
121+
/// [`Copy`]: ../marker/trait.Copy.html
122+
/// [`write`]: fn.write.html
123+
/// [`zero_memory`]: fn.zero_memory.html
124+
/// [`copy_memory`]: fn.copy_memory.html
119125
///
120126
/// # Examples
121127
///
@@ -190,11 +196,17 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
190196
/// # Safety
191197
///
192198
/// Beyond accepting a raw pointer, this is unsafe because it semantically
193-
/// moves the value out of `src` without preventing further usage of `src`.
194-
/// If `T` is not `Copy`, then care must be taken to ensure that the value at
195-
/// `src` is not used before the data is overwritten again (e.g. with `write`,
196-
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
197-
/// because it will attempt to drop the value previously at `*src`.
199+
/// moves the value out of `src` without preventing further usage of `src`. If
200+
/// `T` is not [`Copy`], then care must be taken to ensure that the value at
201+
/// `src` is not used before the data is overwritten again (e.g. with
202+
/// [`write`], [`zero_memory`], or [`copy_memory`]). Note that `*src = foo`
203+
/// counts as a use because it will attempt to drop the value previously at
204+
/// `*src`.
205+
///
206+
/// [`Copy`]: ../marker/trait.Copy.html
207+
/// [`write`]: fn.write.html
208+
/// [`zero_memory`]: fn.zero_memory.html
209+
/// [`copy_memory`]: fn.copy_memory.html
198210
///
199211
/// # Examples
200212
///

0 commit comments

Comments
 (0)