Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add links to interesting items in std::ptr documentation #35880

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 16 additions & 10 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@ 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`]). 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
///
Expand Down Expand Up @@ -206,11 +209,14 @@ 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`]). 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
///
Expand Down